[][src]Trait swim_mem::alloc::Hold

pub unsafe trait Hold<'a> {
    unsafe fn alloc(&self, layout: Layout) -> Result<Block<'a>, HoldError>;
unsafe fn dealloc(&self, block: Block<'a>) -> usize;
unsafe fn resize(
        &self,
        block: Block<'a>,
        layout: Layout
    ) -> Result<Block<'a>, HoldError>; unsafe fn realloc(
        &self,
        block: Block<'a>,
        layout: Layout
    ) -> Result<Block<'a>, HoldError> { ... } }

Limited lifetime memory allocator.

Safety

Every Hold implementation that directly allocates memory blocks must have a valid Reified vtable as its first struct member. The Reified vtable must point to the vtable of the concrete Hold implementation.

Each memory block allocated by a Hold must have an AllocTag in the bytes immediately preceding the block. The tag must contain a valid thin pointer to a Reified struct that, when reified to a Hold trait object, can deallocate the tagged block.

Required methods

unsafe fn alloc(&self, layout: Layout) -> Result<Block<'a>, HoldError>

Returns an unmanaged pointer to an uninitialized memory block sized and aligned to layout; returns an Err if the allocation fails. The allocated block will have a valid AllocTag in the bytes immediately preceding the block.

unsafe fn dealloc(&self, block: Block<'a>) -> usize

Releases a memory block allocated by this Hold. Returns the number of freed bytes.

unsafe fn resize(
    &self,
    block: Block<'a>,
    layout: Layout
) -> Result<Block<'a>, HoldError>

Attempts to resize in place a memory block allocated by this Hold to fit a new layout. Returns Ok with the resized memory block on success; returns a HoldError on failure.

Loading content...

Provided methods

unsafe fn realloc(
    &self,
    block: Block<'a>,
    layout: Layout
) -> Result<Block<'a>, HoldError>

Attempts to resize a memory block allocated by this Hold to fit a new layout. Returns Ok with the resized memory block on success; returns a HoldError on failure.

Loading content...

Methods

impl<'a> dyn Hold<'a>[src]

pub fn global() -> &'a dyn Hold<'a>[src]

Returns a handle to a the global Hold allocator.

pub unsafe fn local() -> &'a dyn Hold<'a>[src]

Returns a handle to a the thread-local Hold allocator.

Safety

Unsafe because the returned reference's lifetime does not necessarily match the lifetime of the current thread local Hold. Callers must take care not to acquire a local Hold reference with a lifetime that exceeds the current thread local Hold.

Panics

Panics if there is no current thread local Hold.

pub fn empty() -> &'a impl Hold<'a>[src]

Returns a reference to a Hold that can only allocate zero-sized values.

Trait Implementations

impl<'a> Reify<'a, dyn Hold<'a> + 'a> for Pack<'a>[src]

Implementors

impl<'a> Hold<'a> for HoldScope<'a>[src]

unsafe fn realloc(
    &self,
    block: Block<'a>,
    layout: Layout
) -> Result<Block<'a>, HoldError>
[src]

impl<'a> Hold<'a> for LocalHold<'a>[src]

unsafe fn realloc(
    &self,
    block: Block<'a>,
    layout: Layout
) -> Result<Block<'a>, HoldError>
[src]

impl<'a> Hold<'a> for Pack<'a>[src]

unsafe fn realloc(
    &self,
    block: Block<'a>,
    layout: Layout
) -> Result<Block<'a>, HoldError>
[src]

impl<'a> Hold<'a> for Pool<'a>[src]

unsafe fn realloc(
    &self,
    block: Block<'a>,
    layout: Layout
) -> Result<Block<'a>, HoldError>
[src]

Loading content...