Trait scoped_allocator::Allocator [] [src]

pub unsafe trait Allocator {
    unsafe fn allocate_raw(
        &self,
        size: usize,
        align: usize
    ) -> Result<*mut u8, AllocatorError>; unsafe fn deallocate_raw(&self, ptr: *mut u8, size: usize, align: usize); fn allocate_val<'a, T>(
        &'a self,
        val: T
    ) -> Result<Allocated<'a, T, Self>, (AllocatorError, T)>
    where
        Self: Sized
, { ... } fn allocate<'a, T>(&'a self) -> Result<Place<'a, T, Self>, AllocatorError>
    where
        Self: Sized
, { ... } }

A custom memory allocator.

Required Methods

Attempt to allocate a block of memory.

Returns either a pointer to the block of memory allocated or an Error. If size is equal to 0, the pointer returned must be equal to heap::EMPTY

Safety

Never use the pointer outside of the lifetime of the allocator. It must be deallocated with the same allocator as it was allocated with. It is undefined behavior to provide a non power-of-two align.

Deallocate the memory referred to by this pointer.

Safety

This pointer must have been allocated by this allocator. The size and align must be the same as when they were allocated. Do not deallocate the same pointer twice. Behavior is implementation-defined, but usually it will not behave as expected.

Provided Methods

Attempts to allocate space for the value supplied to it. This incurs an expensive memcpy. If the performance of this allocation is important to you, it is recommended to use the in-place syntax with the allocate function.

Attempts to create a place to allocate into.

Implementors