pub struct TrackingAllocator<A> { /* private fields */ }
Expand description
A global allocator that tracks allocations on a per-group basis.
This allocator provides the ability to track the allocations/deallocations, both in bytes and objects, for different, user-defined allocation groups.
§Allocation groups
Allocation (and deallocations) are tracked by allocation group. When this allocator is used, every allocation is associated with an allocation group. Allocation groups are user-defined, except for the default “root” allocation group which acts as a catch-all for allocations when a user-defined group is not entered.
§Token guard
When an allocation group is registered, an AllocationGroupToken
is returned. This token can be used to “enter” the
group, which attribute all allocations on the current thread to that group. Entering the group returns a drop guard
that restores the previously entered allocation when it is dropped.
This allows for arbitrarily nested allocation groups.
§Changes to memory layout
In order to associate an allocation with the current allocation group, a small trailer is added to the requested allocation layout, in the form of a pointer to the statistics for the allocation group. This allows updating the statistics directly when an allocation is deallocated, without having to externally keep track of what group a given allocation belongs to. These statistics are updated directly when the allocation is initially made, and when it is deallocated.
This means that all requested allocations end up being one machine word larger: 4 bytes on 32-bit systems, and 8 bytes on 64-bit systems.
Implementations§
Source§impl<A> TrackingAllocator<A>
impl<A> TrackingAllocator<A>
Trait Implementations§
Source§impl<A> GlobalAlloc for TrackingAllocator<A>where
A: GlobalAlloc,
impl<A> GlobalAlloc for TrackingAllocator<A>where
A: GlobalAlloc,
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
layout
. Read moreAuto Trait Implementations§
impl<A> Freeze for TrackingAllocator<A>where
A: Freeze,
impl<A> RefUnwindSafe for TrackingAllocator<A>where
A: RefUnwindSafe,
impl<A> Send for TrackingAllocator<A>where
A: Send,
impl<A> Sync for TrackingAllocator<A>where
A: Sync,
impl<A> Unpin for TrackingAllocator<A>where
A: Unpin,
impl<A> UnwindSafe for TrackingAllocator<A>where
A: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Track for T
impl<T> Track for T
Source§fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self> ⓘ
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self> ⓘ
Tracked
wrapper. Read more