-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
This is probably not a big deal, I just wanted to mention it because it surprised me when I first realized it ...
Lines 197 to 202 in adc60db
| let mem = alloc::alloc(layout); | |
| mem.cast::<Header>().write(Header { | |
| read: AtomicUsize::new(0), | |
| write: AtomicUsize::new(0), | |
| }); | |
| Box::from_raw(ptr::slice_from_raw_parts_mut(mem, capacity) as *mut Self).into() |
After allocating all memory, the Box is converted to an Arc which allocates completely new memory and copies the initialized values to it. AFAICT, the originally allocated memory is deallocated again at the end of the new() method.
Is this intentional?
Or am I missing something?
I found this when trying to convert my own SPSC ring buffer to a DST (see mgeier/rtrb#75), where this crate's code was very helpful. I avoided the repeated allocation by manually implementing a small subset of Arc for this special case instead of using Arc directly.
Metadata
Metadata
Assignees
Labels
No labels