NSTDAllocator

Struct NSTDAllocator 

Source
#[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, }
Available on crate feature core only.
Expand description

A structure of function pointers making up an allocator’s virtual function table.

Fields§

§state: NSTDAny

An opaque pointer to the allocator’s state.

§allocate: unsafe extern "C" fn(NSTDAny, NSTDAllocLayout) -> NSTDAnyMut

Allocates 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) -> NSTDAnyMut

Allocates 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) -> NSTDAllocError

Reallocates 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 ptr is not a pointer to memory allocated by this allocator.

  • old_layout must be the same value that was used to allocate the memory buffer.

§deallocate: unsafe extern "C" fn(NSTDAny, NSTDAnyMut, NSTDAllocLayout) -> NSTDAllocError

Deallocates memory that was previously allocated by this allocator.

§Parameters:

  • NSTDAnyMut ptr - A pointer to the allocated memory.

  • NSTDAllocLayout layout - Describes the layout of memory that ptr points to.

§Returns

NSTDAllocError errc - The allocation operation error code.

§Safety

  • Behavior is undefined if ptr is not a pointer to memory allocated by this allocator.

  • layout must be the same value that was used to allocate the memory buffer.

Trait Implementations§

Source§

impl Clone for NSTDAllocator

Source§

fn clone(&self) -> NSTDAllocator

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for NSTDAllocator

Source§

impl Send for NSTDAllocator

§Safety

The allocator’s state must be able to be safely shared between threads.

Source§

impl Sync for NSTDAllocator

§Safety

The allocator’s state must be able to be safely shared between threads.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.