-
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
Change the signatures of AllocRef
to take self
instead of &mut self
#37
Comments
This makes sense to me. Also:
This is cool. |
Just a small docs note: if the methods take
because implementing It should also be noted that methods by |
Yes, that's true. unsafe impl<T: GlobalAlloc> AllocRef for &T { ... } |
Unless the smart pointers are |
At least at the playground this works quite well: fn test_alloc<T, A: GlobalAlloc>(alloc: A) {
let layout = Layout::new::<T>();
let p = AllocRef::alloc(&alloc, layout).expect("Failed to allocate");
unsafe {
AllocRef::dealloc(&alloc, p, layout);
}
} |
Yes, it definitely will work (and will continue working) when proxied through What I'm raising a concern for is if/when |
I experimented a lot with
Even without the last point, collections like |
For an example how to implement shareable allocators please see the example in the RFC. |
Works for me 👌🏻 |
@TimDiekmann Shouldn't the problem you mention be solved by the fact that you require |
@JelteF trait AllocRef: Copy {}
#[derive(Copy, Clone)]
struct MyAlloc {}
// works
impl AllocRef for MyAlloc {}
// E0277
impl AllocRef for &mut MyAlloc {}
|
The gamedev WG made a proof of concept with our new
AllocRef
andBuildAllocRef
trait (implemented at thealloc-wg
crate) by implementing them forbumpalo
.It turned out, as mentioned in TimDiekmann/alloc-wg#11, that taking
&mut self
isn't always the best way to implementAllocRef
. I would like to recall once again thatAllocRef
should not be implemented on stateful structs. That was the reason why we renamedAlloc
toAllocRef
in #8.@Wodann and I discussed a bit about this problem in the gamedev discord channel and my suggestion is to take
self
instead of&mut self
. This solves several issues:AllocRef
can be implemented on ZST types as before (e.g.Global
andSystem
)For non-ZST and non-This does not work at all -> ClosedCopy
types, the user can chose between implementing it on&MyAllocator
and&mut MyAllocator
AllocRef
for actual references #34The resulting API would look like this:
The text was updated successfully, but these errors were encountered: