[−][src]Trait swim_mem::alloc::Hold
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>
&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.
Provided methods
unsafe fn realloc(
&self,
block: Block<'a>,
layout: Layout
) -> Result<Block<'a>, HoldError>
&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.
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
Implementors
impl<'a> Hold<'a> for HoldScope<'a>
[src]
unsafe fn alloc(&self, layout: Layout) -> Result<Block<'a>, HoldError>
[src]
unsafe fn dealloc(&self, _block: Block<'a>) -> usize
[src]
unsafe fn resize(
&self,
_block: Block<'a>,
_layout: Layout
) -> Result<Block<'a>, HoldError>
[src]
&self,
_block: Block<'a>,
_layout: Layout
) -> Result<Block<'a>, HoldError>
unsafe fn realloc(
&self,
block: Block<'a>,
layout: Layout
) -> Result<Block<'a>, HoldError>
[src]
&self,
block: Block<'a>,
layout: Layout
) -> Result<Block<'a>, HoldError>
impl<'a> Hold<'a> for LocalHold<'a>
[src]
unsafe fn alloc(&self, layout: Layout) -> Result<Block<'a>, HoldError>
[src]
unsafe fn dealloc(&self, _block: Block<'a>) -> usize
[src]
unsafe fn resize(
&self,
_block: Block<'a>,
_layout: Layout
) -> Result<Block<'a>, HoldError>
[src]
&self,
_block: Block<'a>,
_layout: Layout
) -> Result<Block<'a>, HoldError>
unsafe fn realloc(
&self,
block: Block<'a>,
layout: Layout
) -> Result<Block<'a>, HoldError>
[src]
&self,
block: Block<'a>,
layout: Layout
) -> Result<Block<'a>, HoldError>
impl<'a> Hold<'a> for Pack<'a>
[src]
unsafe fn alloc(&self, layout: Layout) -> Result<Block<'a>, HoldError>
[src]
unsafe fn dealloc(&self, block: Block<'a>) -> usize
[src]
unsafe fn resize(
&self,
block: Block<'a>,
layout: Layout
) -> Result<Block<'a>, HoldError>
[src]
&self,
block: Block<'a>,
layout: Layout
) -> Result<Block<'a>, HoldError>
unsafe fn realloc(
&self,
block: Block<'a>,
layout: Layout
) -> Result<Block<'a>, HoldError>
[src]
&self,
block: Block<'a>,
layout: Layout
) -> Result<Block<'a>, HoldError>
impl<'a> Hold<'a> for Pool<'a>
[src]
unsafe fn alloc(&self, layout: Layout) -> Result<Block<'a>, HoldError>
[src]
unsafe fn dealloc(&self, _block: Block<'a>) -> usize
[src]
unsafe fn resize(
&self,
_block: Block<'a>,
_layout: Layout
) -> Result<Block<'a>, HoldError>
[src]
&self,
_block: Block<'a>,
_layout: Layout
) -> Result<Block<'a>, HoldError>
unsafe fn realloc(
&self,
block: Block<'a>,
layout: Layout
) -> Result<Block<'a>, HoldError>
[src]
&self,
block: Block<'a>,
layout: Layout
) -> Result<Block<'a>, HoldError>