Struct Dlmalloc

Source
pub struct Dlmalloc(/* private fields */);
Expand description

An allocator instance

Instances of this type are used to allocate blocks of memory. For best results only use one of these. Currently doesn’t implement Drop to release lingering memory back to the OS. That may happen eventually though!

Implementations§

Source§

impl Dlmalloc

Source

pub fn new() -> Dlmalloc

Creates a new instance of an allocator, same as DLMALLOC_INIT.

Source

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

Allocates size bytes with align align.

Returns a null pointer if allocation fails. Returns a valid pointer otherwise.

Safety and contracts are largely governed by the GlobalAlloc::alloc method contracts.

Source

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

Same as malloc, except if the allocation succeeds it’s guaranteed to point to size bytes of zeros.

Source

pub unsafe fn free(&mut self, ptr: *mut u8, _size: usize, _align: usize)

Deallocates a ptr with size and align as the previous request used to allocate it.

Safety and contracts are largely governed by the GlobalAlloc::dealloc method contracts.

Source

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

Reallocates ptr, a previous allocation with old_size and old_align, to have new_size and the same alignment as before.

Returns a null pointer if the memory couldn’t be reallocated, but ptr is still valid. Returns a valid pointer and frees ptr if the request is satisfied.

Safety and contracts are largely governed by the GlobalAlloc::realloc method contracts.

Source

pub unsafe fn get_alloced_mem_size(&self) -> usize

Returns alloced mem size

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 = 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.