-
Notifications
You must be signed in to change notification settings - Fork 9
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
Is something like realloc_zeroed
and grow_in_place_zeroed
useful?
#14
Comments
+1 Implementation-wise for large reallocations there's definitely cases where allocators can efficiently do things like mmap additional (zeroed) pages to the end of an allocation. Also can have a default implementation that just forwards to |
I think these two can be useful. Whether these are worth having in an MVP, I don't know, we can always add them later. |
Shall we introduce a Currently, zeroed allocation is pretty error prone and even experienced users may miss this: rust-lang/rust#63291 (comment). On the other hand, we would restrict implementations which are fine to get zeroed layout like a bump allocator.
Please vote with
|
This seems like maybe it's about two things. Is this about having newly allocated memory blocks already be zeroed? |
It's just like |
Ah, that's very good, but i agree that it's not really necessary for the minimum "get something working" stage. Voted. |
It would be better to have these before stabilizing AllocRef. |
I think stabilizing the whole thing will take at least one year |
I also wouldn't actually stabilize AllocRef without this But it's low priority to just get people using AllocRef and get people hammering on usage problems in Nightly and so on. |
I like to mention though, that implementing those function is trivial and straight forward. But we shouldn't clutter the trait unless it's more or less fixed. |
I find it hard to make a call on this one for the following reasons:
pub fn alloc_with<F>(self, layout: Layout, f: F) -> Result<NonNull<u8>, AllocErr>
where
F: FnOnce(ptr: NonNull<u8>, size: usize) -> NonNull<u8>; |
I think these should be added since they can be efficiently implemented with the If |
Add missing `_zeroed` varants to `AllocRef` The majority of the allocator wg has decided to add the missing `_zeroed` variants to `AllocRef`: > these should be added since they can be efficiently implemented with the `mremap` system call on Linux. `mremap` allows you to move/grow/shrink a memory mapping, and any new pages added for growth are guaranteed to be zeroed. > > If `AllocRef` does not have these methods then the user will have to manually write zeroes to the added memory since the API makes no guarantees on their contents. For the full discussion please see rust-lang/wg-allocators#14. This PR provides default implementations for `realloc_zeroed`, `alloc_excess_zeroed`, `realloc_excess_zeroed`, and `grow_in_place_zeroed`. r? @Amanieu
Add missing `_zeroed` varants to `AllocRef` The majority of the allocator wg has decided to add the missing `_zeroed` variants to `AllocRef`: > these should be added since they can be efficiently implemented with the `mremap` system call on Linux. `mremap` allows you to move/grow/shrink a memory mapping, and any new pages added for growth are guaranteed to be zeroed. > > If `AllocRef` does not have these methods then the user will have to manually write zeroes to the added memory since the API makes no guarantees on their contents. For the full discussion please see rust-lang/wg-allocators#14. This PR provides default implementations for `realloc_zeroed`, `alloc_excess_zeroed`, `realloc_excess_zeroed`, and `grow_in_place_zeroed`. r? @Amanieu
When growing an allocation, is there a reason why there is no method that guarantees that the new memory is zeroed?
The text was updated successfully, but these errors were encountered: