Trait dlmalloc::Allocator[][src]

pub unsafe trait Allocator: Send {
    fn alloc(&self, size: usize) -> (*mut u8, usize, u32);
fn remap(
        &self,
        ptr: *mut u8,
        oldsize: usize,
        newsize: usize,
        can_move: bool
    ) -> *mut u8;
fn free_part(&self, ptr: *mut u8, oldsize: usize, newsize: usize) -> bool;
fn free(&self, ptr: *mut u8, size: usize) -> bool;
fn can_release_part(&self, flags: u32) -> bool;
fn allocates_zeros(&self) -> bool;
fn page_size(&self) -> usize; }
Expand description

In order for this crate to efficiently manage memory, it needs a way to communicate with the underlying platform. This Allocator trait provides an interface for this communication.

Required methods

Allocates system memory region of at least size bytes Returns a triple of (base, size, flags) where base is a pointer to the beginning of the allocated memory region. size is the actual size of the region while flags specifies properties of the allocated region. If EXTERN_BIT (bit 0) set in flags, then we did not allocate this segment and so should not try to deallocate or merge with others. This function can return a std::ptr::null_mut() when allocation fails (other values of the triple will be ignored).

Remaps system memory region at ptr with size oldsize to a potential new location with size newsize. can_move indicates if the location is allowed to move to a completely new location, or that it is only allowed to change in size. Returns a pointer to the new location in memory. This function can return a std::ptr::null_mut() to signal an error.

Frees a part of a memory chunk. The original memory chunk starts at ptr with size oldsize and is turned into a memory region starting at the same address but with newsize bytes. Returns true iff the access memory region could be freed.

Frees an entire memory region. Returns true iff the operation succeeded. When false is returned, the dlmalloc may re-use the location on future allocation requests

Indicates if the system can release a part of memory. For the flags argument, see Allocator::alloc

Indicates whether newly allocated regions contain zeros.

Returns the page size. Must be a power of two

Implementors