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 resource groups.
§Resource groups
Allocation (and deallocations) are tracked by resource group. When this allocator is used, every allocation is associated with an resource group. Resource groups are user-defined, except for the default “root” resource group which acts as a catch-all when a user-defined group isn’t currently entered.
§Token guard
When an resource group is registered, an ResourceGroupToken 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’s dropped.
This allows for arbitrarily nested resource groups.
§Changes to memory layout
In order to associate an allocation with the current resource group, a small trailer is added to the requested allocation layout, in the form of a pointer to the statistics for the resource 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’s 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> UnsafeUnpin for TrackingAllocator<A>where
A: UnsafeUnpin,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Track for T
impl<T> Track for T
Source§fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self> ⓘ
fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self> ⓘ
Tracked wrapper. Read more