-
Notifications
You must be signed in to change notification settings - Fork 323
Add .shrink_to_fit() method for Array #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello! For example, suppose you have an
An easy solution I can think of is to record the |
For owned arrays, you can determine this offset by the following snippet (copied from the let data_to_array_offset = if std::mem::size_of::<A>() != 0 {
self.as_ptr().offset_from(self.data.as_ptr())
} else {
0
};
debug_assert!(data_to_array_offset >= 0); The |
Some methods (e.g.
.remove_axis()
,.into_subview()
, and.slice_move()
) can cause some of the elements in an owned array to be come inaccessable. It would be useful to have a method that removes the inaccessable elements (to reduce memory usage without performing a new heap allocation) by shifting the remaining elements to the front of the underlyingVec
and shrinking theVec
. See the discussion in #425, in particular this comment for some thoughts about the implementation.The text was updated successfully, but these errors were encountered: