-
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
What about AllocRef and SyncAllocRef? #71
Comments
This comment has been minimized.
This comment has been minimized.
@TimDiekmann Yeah, I see. That is unfortunate. My other idea is that there could be two allocator traits, It'd look something like this: pub unsafe trait SyncAllocRef: Sync + Send {
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr>;
unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout);
// ...
}
unsafe impl<A> AllocRef for A where A: SyncAllocRef {
fn alloc(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
<Self as SyncAllocRef>::alloc(self, layout)
}
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
<Self as SyncAllocRef>::dealloc(self, ptr, layout)
}
} Then, regular collections could just take an It's explicit, idiomatic in all circumstances, and doesn't result in performance pitfalls. |
self
been ruled out?
The idea isn't new, but I totally forgot about this approach, thank you for bringing this back! However I think this should be discussed in #55. I close this in favor of the other issue. |
I feel like this would provide the most ergonomic solution for working with both single-threaded and multi-threaded collections.For a stack allocator, you'd pass&mut A
into the collection. For a collection like a shared hashmap, you'd use an allocator that supported concurrent allocations and pass in&A
.AllocRef
would be implemented for either&A
and&mut A
depending on if it was concurrent or not.It's definitely possible I'm not seeing some downsides of this, but it seems like the best of both worlds to me.See my reply lower down.
The text was updated successfully, but these errors were encountered: