Skip to main content

MmapHeap

Struct MmapHeap 

Source
pub struct MmapHeap { /* private fields */ }
Expand description

Dynamic virtual-memory allocator backed by mmap_anonymous slabs for small blocks (<= 4080 bytes) and direct page-granularity mmap_anonymous/munmap mappings for large or over-aligned allocations.

Implementations§

Source§

impl MmapHeap

Source

pub const fn new() -> Self

Creates a new uninitialized MmapHeap.

Source

pub unsafe fn alloc_c(&self, size: usize, align: usize) -> *mut u8

Allocates size bytes with alignment align (at least 16-byte aligned), recording C-compatible metadata immediately preceding the returned user pointer.

§Safety

Any non-null pointer returned must be released via MmapHeap::free_c or MmapHeap::realloc_c.

Source

pub unsafe fn calloc_c(&self, nobj: usize, size: usize) -> *mut u8

Allocates and zero-initializes nobj * size bytes.

§Safety

Any non-null pointer returned must be released via MmapHeap::free_c or MmapHeap::realloc_c.

Source

pub unsafe fn free_c(&self, ptr: *mut u8)

Frees a pointer previously returned by MmapHeap::alloc_c, MmapHeap::calloc_c, or MmapHeap::realloc_c. Passing null is a safe no-op.

§Safety

ptr must be null or a live pointer allocated by this MmapHeap.

Source

pub unsafe fn realloc_c(&self, ptr: *mut u8, new_size: usize) -> *mut u8

Resizes an existing allocation to new_size bytes.

§Safety

ptr must be null or a live pointer allocated by this MmapHeap.

Source

pub unsafe fn posix_memalign_c( &self, out: *mut *mut u8, align: usize, size: usize, ) -> i32

POSIX-compatible aligned allocation writing the result into *out.

§Safety

out must be a valid non-null writable pointer to *mut u8.

Trait Implementations§

Source§

impl Default for MmapHeap

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl GlobalAlloc for MmapHeap

Source§

unsafe fn alloc(&self, layout: Layout) -> *mut u8

Allocates memory as described by the given layout. Read more
Source§

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8

Behaves like alloc, but also ensures that the contents are set to zero before being returned. Read more
Source§

unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout)

Deallocates the block of memory at the given ptr pointer with the given layout. Read more
Source§

unsafe fn realloc( &self, ptr: *mut u8, layout: Layout, new_size: usize, ) -> *mut u8

Shrinks or grows a block of memory to the given new_size in bytes. The block is described by the given ptr pointer and layout. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.