Struct nstd_sys::alloc::NSTDAllocator
source · #[repr(C)]pub struct NSTDAllocator {
pub state: NSTDAny,
pub allocate: unsafe extern "C" fn(_: NSTDAny, _: NSTDUInt) -> NSTDAnyMut,
pub allocate_zeroed: unsafe extern "C" fn(_: NSTDAny, _: NSTDUInt) -> NSTDAnyMut,
pub reallocate: unsafe extern "C" fn(_: NSTDAny, _: &mut NSTDAnyMut, _: NSTDUInt, _: NSTDUInt) -> NSTDAllocError,
pub deallocate: unsafe extern "C" fn(_: NSTDAny, _: &mut NSTDAnyMut, _: NSTDUInt) -> NSTDAllocError,
}alloc only.Expand description
A structure of function pointers making up an allocator VTable.
Fields§
§state: NSTDAnyAn opaque pointer to the allocator’s state.
allocate: unsafe extern "C" fn(_: NSTDAny, _: NSTDUInt) -> NSTDAnyMutAllocates a contiguous sequence of size bytes in memory.
If allocation fails, a null pointer is returned.
If allocation succeeds, this returns a pointer that is suitably aligned for any type with fundamental alignment, i.e., the returned pointer will be suitably aligned for max_align_t.
Allocation will fail if size is greater than NSTDInt’s max value.
Parameters:
NSTDUInt size- The number of bytes to allocate.
Returns
NSTDAnyMut ptr - A pointer to the allocated memory, null on error.
Safety
-
Behavior is undefined if
sizeis zero. -
The new memory buffer should be considered uninitialized.
allocate_zeroed: unsafe extern "C" fn(_: NSTDAny, _: NSTDUInt) -> NSTDAnyMutAllocates a contiguous sequence of size bytes in memory.
The initialized memory is zero-initialized.
If allocation fails, a null pointer is returned.
If allocation succeeds, this returns a pointer that is suitably aligned for any type with fundamental alignment, i.e., the returned pointer will be suitably aligned for max_align_t.
Allocation will fail if size is greater than NSTDInt’s max value.
Parameters:
NSTDUInt size- The number of bytes to allocate.
Returns
NSTDAnyMut ptr - A pointer to the allocated memory, null on error.
Safety
-
Behavior is undefined if
sizeis zero. -
The new memory buffer should be considered uninitialized.
reallocate: unsafe extern "C" fn(_: NSTDAny, _: &mut NSTDAnyMut, _: NSTDUInt, _: NSTDUInt) -> NSTDAllocErrorReallocates memory that was previously allocated by this allocator.
Reallocation will fail if new_size is greater than NSTDInt’s max value.
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. -
NSTDUInt size- The number of bytes currently allocated. -
NSTDUInt new_size- The number of bytes to reallocate.
Returns
NSTDAllocError errc - The allocation operation error code.
Safety
-
Behavior is undefined if
new_sizeis zero. -
Behavior is undefined if
ptris not a value returned by this allocator. -
sizemust be the same value that was used to allocate the memory buffer.
deallocate: unsafe extern "C" fn(_: NSTDAny, _: &mut NSTDAnyMut, _: NSTDUInt) -> NSTDAllocErrorDeallocates memory that was previously allocated by this allocator.
On successful deallocation, ptr will be set to null and NSTD_ALLOC_ERROR_NONE will be
returned. If this is not the case and deallocation fails, the pointer will remain untouched
and the appropriate error is returned.
Parameters:
-
NSTDAnyMut *ptr- A pointer to the allocated memory, once freed the pointer is set to null. -
NSTDUInt size- The number of bytes currently allocated.
Returns
NSTDAllocError errc - The allocation operation error code.
Safety
-
Behavior is undefined if
ptris not a value returned by this allocator. -
sizemust 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.