Region

Trait Region 

Source
pub trait Region<H> {
    type Pointers: Iterator<Item = *mut u8>;

    // Required methods
    fn allocate(&mut self, layout: Layout, header: H) -> Result<*mut u8, H>;
    fn deallocate(&mut self, ptr: *mut u8) -> Option<H>;
    fn has_allocated(&self, ptr: *mut u8) -> bool;
    fn allocations(&self) -> Self::Pointers;
    fn count(&self) -> usize;

    // Provided method
    fn deallocate_all(&mut self) -> DeallocateAll<'_, H, Self>
       where Self: Sized { ... }
}
Expand description

Represents a region of the memory. Objects can be allocated into this region. Regions can carry additional data with each allocation.

Required Associated Types§

Source

type Pointers: Iterator<Item = *mut u8>

An iterator over all the allocations of this region.

Required Methods§

Source

fn allocate(&mut self, layout: Layout, header: H) -> Result<*mut u8, H>

Finds a free location within this region that is:

  • Properly aligned to layout.align
  • layout.size bytes long
§Returns

The pointer is returned if the allocation is successful and the provided header is given back in the error if the allocation could not be done.

Source

fn deallocate(&mut self, ptr: *mut u8) -> Option<H>

Deallocates the memory allocated at the given pointer.

§Returns

If the given pointer was not allocated in this region, None is returned. Otherwise, the header is returned.

§Safety
  • The old value must’ve been properly dropped.
Source

fn has_allocated(&self, ptr: *mut u8) -> bool

Checks whether the given pointer is allocated in this region.

Source

fn allocations(&self) -> Self::Pointers

Returns an iterator over all the allocations of this region.

Source

fn count(&self) -> usize

Returns the number of allocations this region has.

Provided Methods§

Source

fn deallocate_all(&mut self) -> DeallocateAll<'_, H, Self>
where Self: Sized,

Returns an iterator that causes all allocations to be deallocated. The iterator yield the headers.

Implementors§