[−][src]Trait alloc_traits::LocalAlloc
An allocator providing memory regions valid for a particular lifetime.
It is useful to compare this trait to std::alloc::GlobalAlloc
. Similar to the trait it is
required that the implementors adhere to the contract of the methods.
Required methods
fn alloc(&'alloc self, layout: NonZeroLayout) -> Option<Allocation<'alloc>>
Allocate one block of memory.
The callee guarantees that a successful return contains a pointer that is valid for at least the layout requested by the caller.
unsafe fn dealloc(&'alloc self, alloc: Allocation<'alloc>)
Deallocate a block previously allocated.
Safety
The caller must ensure that:
alloc
has been previously returned from a call toalloc
.- There are no more pointer to the allocation.
Provided methods
fn alloc_zeroed(
&'alloc self,
layout: NonZeroLayout
) -> Option<Allocation<'alloc>>
&'alloc self,
layout: NonZeroLayout
) -> Option<Allocation<'alloc>>
Allocate a block of memory initialized with zeros.
The callee guarantees that a successful return contains a pointer that is valid for at least the layout requested by the caller and the contiguous region of bytes, starting at the pointer and with the size of the returned layout, is initialized and zeroed.
unsafe fn realloc(
&'alloc self,
alloc: Allocation<'alloc>,
layout: NonZeroLayout
) -> Option<Allocation<'alloc>>
&'alloc self,
alloc: Allocation<'alloc>,
layout: NonZeroLayout
) -> Option<Allocation<'alloc>>
Change the layout of a block previously allocated.
The callee guarantees that a successful return contains a pointer that is valid for at least the layout requested by the caller and the contiguous region of bytes, starting at the pointer and with the size of the returned layout, is initialized with the prefix of the previous allocation that is still valid.
Note that it is NOT safe to elide the methods call for changing the alignment of the layout to a less strict one, or to an incidentally fulfilled stricter version. The allocator might make use of the alignment during deallocation.