Struct resources::address_allocator::AddressAllocator  
source · pub struct AddressAllocator {
    pools: Vec<AddressRange>,
    min_align: u64,
    preferred_align: u64,
    allocs: HashMap<Alloc, (AddressRange, String)>,
    regions: BTreeSet<AddressRange>,
}Expand description
Manages allocating address ranges.
Use AddressAllocator whenever an address range needs to be allocated to different users.
Allocations must be uniquely tagged with an Alloc enum, which can be used for lookup.
An human-readable tag String must also be provided for debugging / reference.
Fields§
§pools: Vec<AddressRange>The list of pools from which address are allocated. The union of all regions from |allocs| and |regions| equals the pools.
min_align: u64§preferred_align: u64§allocs: HashMap<Alloc, (AddressRange, String)>The region that is allocated.
regions: BTreeSet<AddressRange>The region that is not allocated yet.
Implementations§
source§impl AddressAllocator
 
impl AddressAllocator
sourcepub fn new(
    pool: AddressRange,
    min_align: Option<u64>,
    preferred_align: Option<u64>,
) -> Result<Self>
 
pub fn new( pool: AddressRange, min_align: Option<u64>, preferred_align: Option<u64>, ) -> Result<Self>
Creates a new AddressAllocator for managing a range of addresses.
Can return an error if pool is empty or if alignment isn’t a power of two.
pool- The address range to allocate from.min_align- The minimum size of an address region to align to, defaults to four.preferred_align- The preferred alignment of an address region, used if possible.
If an allocation cannot be satisfied with the preferred alignment, the minimum alignment will be used instead.
sourcepub fn new_from_list<T>(
    pools: T,
    min_align: Option<u64>,
    preferred_align: Option<u64>,
) -> Result<Self>where
    T: IntoIterator<Item = AddressRange>,
 
pub fn new_from_list<T>(
    pools: T,
    min_align: Option<u64>,
    preferred_align: Option<u64>,
) -> Result<Self>where
    T: IntoIterator<Item = AddressRange>,
Creates a new AddressAllocator for managing a range of addresses.
Can return None if all pools are empty alignment isn’t a power of two.
pools- The list of pools to initialize the allocator with.min_align- The minimum size of an address region to align to, defaults to four.preferred_align- The preferred alignment of an address region, used if possible.
If an allocation cannot be satisfied with the preferred alignment, the minimum alignment will be used instead.
sourcepub fn pools(&self) -> &[AddressRange]
 
pub fn pools(&self) -> &[AddressRange]
Gets the regions managed by the allocator.
This returns the original pools value provided to AddressAllocator::new().
fn internal_allocate_from_slot( &mut self, slot: AddressRange, range: AddressRange, alloc: Alloc, tag: String, ) -> Result<u64>
fn internal_allocate_with_align( &mut self, size: u64, alloc: Alloc, tag: String, alignment: u64, reverse: bool, ) -> Result<u64>
sourcepub fn reverse_allocate_with_align(
    &mut self,
    size: u64,
    alloc: Alloc,
    tag: String,
    alignment: u64,
) -> Result<u64>
 
pub fn reverse_allocate_with_align( &mut self, size: u64, alloc: Alloc, tag: String, alignment: u64, ) -> Result<u64>
Allocates a range of addresses from the reverse managed region with an optional tag
and minimal alignment. Returns allocated_address. (allocated_address, size, tag)
can be retrieved through the get method.
sourcepub fn reverse_allocate(
    &mut self,
    size: u64,
    alloc: Alloc,
    tag: String,
) -> Result<u64>
 
pub fn reverse_allocate( &mut self, size: u64, alloc: Alloc, tag: String, ) -> Result<u64>
Allocates a range of addresses, preferring to allocate from high rather than low addresses.
sourcepub fn allocate_with_align(
    &mut self,
    size: u64,
    alloc: Alloc,
    tag: String,
    alignment: u64,
) -> Result<u64>
 
pub fn allocate_with_align( &mut self, size: u64, alloc: Alloc, tag: String, alignment: u64, ) -> Result<u64>
Allocates a range of addresses from the managed region with an optional tag
and minimal alignment. Returns allocated_address. (allocated_address, size, tag)
can be retrieved through the get method.
pub fn allocate(&mut self, size: u64, alloc: Alloc, tag: String) -> Result<u64>
sourcepub fn allocate_at(
    &mut self,
    range: AddressRange,
    alloc: Alloc,
    tag: String,
) -> Result<()>
 
pub fn allocate_at( &mut self, range: AddressRange, alloc: Alloc, tag: String, ) -> Result<()>
Allocates a range of addresses from the managed region with an optional tag and required location. Allocation alignment is not enforced. Returns OutOfSpace if requested range is not available or ExistingAlloc if the requested range overlaps an existing allocation.
sourcepub fn release(&mut self, alloc: Alloc) -> Result<AddressRange>
 
pub fn release(&mut self, alloc: Alloc) -> Result<AddressRange>
Releases exising allocation back to free pool and returns the range that was released.
sourcepub fn release_containing(&mut self, value: u64) -> Result<AddressRange>
 
pub fn release_containing(&mut self, value: u64) -> Result<AddressRange>
Release a allocation contains the value.
fn find_overlapping(&self, range: AddressRange) -> Option<Alloc>
pub fn get_max_addr(&self) -> u64
sourcepub fn get(&self, alloc: &Alloc) -> Option<&(AddressRange, String)>
 
pub fn get(&self, alloc: &Alloc) -> Option<&(AddressRange, String)>
Returns allocation associated with alloc, or None if no such allocation exists.
sourcefn insert_at(&mut self, slot: AddressRange) -> Result<()>
 
fn insert_at(&mut self, slot: AddressRange) -> Result<()>
Insert range of addresses into the pool, coalescing neighboring regions.
Trait Implementations§
source§impl Debug for AddressAllocator
 
impl Debug for AddressAllocator
source§impl PartialEq for AddressAllocator
 
impl PartialEq for AddressAllocator
source§fn eq(&self, other: &AddressAllocator) -> bool
 
fn eq(&self, other: &AddressAllocator) -> bool
self and other values to be equal, and is used
by ==.