#[repr(C)]pub struct NSTDAllocator {
pub state: NSTDAny,
pub allocate: unsafe extern "C" fn(NSTDAny, NSTDAllocLayout) -> NSTDAnyMut,
pub allocate_zeroed: unsafe extern "C" fn(NSTDAny, NSTDAllocLayout) -> NSTDAnyMut,
pub reallocate: unsafe extern "C" fn(NSTDAny, &mut NSTDAnyMut, NSTDAllocLayout, NSTDAllocLayout) -> NSTDAllocError,
pub deallocate: unsafe extern "C" fn(NSTDAny, NSTDAnyMut, NSTDAllocLayout) -> NSTDAllocError,
}core only.Expand description
A structure of function pointers making up an allocator’s virtual function table.
Fields§
§state: NSTDAnyAn opaque pointer to the allocator’s state.
allocate: unsafe extern "C" fn(NSTDAny, NSTDAllocLayout) -> NSTDAnyMutAllocates a new block of memory.
If allocation fails, a null pointer is returned.
If allocation succeeds, this returns a pointer to the new memory that is suitably aligned
for layout’s alignment and the number of bytes allocated is at least equal to layout’s
size.
§Parameters:
NSTDAllocLayout layout- Describes the memory layout to allocate for.
§Returns
NSTDAnyMut ptr - A pointer to the allocated memory, null on error.
§Safety
-
Behavior is undefined if
layout’s size is zero. -
The new memory buffer should be considered uninitialized.
allocate_zeroed: unsafe extern "C" fn(NSTDAny, NSTDAllocLayout) -> NSTDAnyMutAllocates a new block of zero-initialized memory.
If allocation fails, a null pointer is returned.
If allocation succeeds, this returns a pointer to the new memory that is suitably aligned
for layout’s alignment and the number of bytes allocated is at least equal to layout’s
size.
§Parameters:
NSTDAllocLayout layout- Describes the memory layout to allocate for.
§Returns
NSTDAnyMut ptr - A pointer to the allocated memory, null on error.
§Safety
Behavior is undefined if layout’s size is zero.
reallocate: unsafe extern "C" fn(NSTDAny, &mut NSTDAnyMut, NSTDAllocLayout, NSTDAllocLayout) -> NSTDAllocErrorReallocates memory that was previously allocated by this allocator.
On successful reallocation, ptr will point to the new memory location and
NSTD_ALLOC_ERROR_NONE will be returned. If this is not the case and reallocation fails,
the pointer will remain untouched and the appropriate error is returned.
§Parameters:
-
NSTDAnyMut *ptr- A pointer to the allocated memory. -
NSTDAllocLayout old_layout- Describes the previous memory layout. -
NSTDAllocLayout new_layout- Describes the new memory layout to allocate for.
§Returns
NSTDAllocError errc - The allocation operation error code.
§Safety
-
Behavior is undefined if
new_layout’s size is zero. -
Behavior is undefined if
ptris not a pointer to memory allocated by this allocator. -
old_layoutmust be the same value that was used to allocate the memory buffer.
deallocate: unsafe extern "C" fn(NSTDAny, NSTDAnyMut, NSTDAllocLayout) -> NSTDAllocErrorDeallocates memory that was previously allocated by this allocator.
§Parameters:
-
NSTDAnyMut ptr- A pointer to the allocated memory. -
NSTDAllocLayout layout- Describes the layout of memory thatptrpoints to.
§Returns
NSTDAllocError errc - The allocation operation error code.
§Safety
-
Behavior is undefined if
ptris not a pointer to memory allocated by this allocator. -
layoutmust be the same value that was used to allocate the memory buffer.
Trait Implementations§
Source§impl Clone for NSTDAllocator
impl Clone for NSTDAllocator
Source§fn clone(&self) -> NSTDAllocator
fn clone(&self) -> NSTDAllocator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for NSTDAllocator
impl Send for NSTDAllocator
§Safety
The allocator’s state must be able to be safely shared between threads.
impl Sync for NSTDAllocator
§Safety
The allocator’s state must be able to be safely shared between threads.