ADC Home > Reference Library > Reference > Darwin > Kernel Framework Reference

 


IORangeAllocator

Inherits from:
Declared In:

Overview

A utility class to manage allocations from a range.

Discussion

The IORangeAllocator class provides functions for allocating ranges, at a fixed or any offset, and freeing them back to a free list. It is useful for describing ranges of memory or address space without requiring storage in the memory - information describing the free elements is kept elsewhere. Ranges are described by a start offset and a size. IORangeAllocator is optionally protected against multithreaded access.



Functions

allocate

Allocates from the free list, at any offset.

allocateRange

Allocates from the free list, at a set offset.

deallocate

Deallocates a range to the free list.

getFragmentCapacity

Accessor to return the number of free fragments in the range.

getFragmentCount

Accessor to return the number of free fragments in the range.

getFreeCount

Totals the sizes of the free fragments.

init

Standard initializer for IORangeAllocator.

setFragmentCapacityIncrement

Sets the count of fragments the free list will increase by when full.

withRange

Standard factory method for IORangeAllocator.


allocate


Allocates from the free list, at any offset.

public

virtual bool allocate( IORangeScalar size, IORangeScalar *result, IORangeScalar alignment = 0 );
Parameters
size

The size of the range requested.

result

The beginning of the range allocated is returned here on success.

alignment

If zero is passed, default to the allocators alignment, otherwise pass an alignment required for the allocation, for example 4096 to page align.

Return Value

Returns true if the allocation was successful, else false.

Discussion

This method allocates a range from the free list. The alignment will default to the alignment set when the allocator was created or may be set here.


allocateRange


Allocates from the free list, at a set offset.

public

virtual bool allocateRange( IORangeScalar start, IORangeScalar size );
Parameters
start

The beginning of the range requested.

size

The size of the range requested.

Return Value

Returns true if the allocation was successful, else false.

Discussion

This method allocates a range from the free list, given a set offset passed in.


deallocate


Deallocates a range to the free list.

public

virtual void deallocate( IORangeScalar start, IORangeScalar size );
Parameters
start

The beginning of the range requested.

size

Returns the size of the range requested.

Discussion

This method deallocates a range to the free list, given a the start offset and length passed in.


getFragmentCapacity


Accessor to return the number of free fragments in the range.

public

virtual UInt32 getFragmentCapacity( void );
Return Value

Returns the current capacity of free fragment list.

Discussion

This method returns the current capacity of the free fragment list.


getFragmentCount


Accessor to return the number of free fragments in the range.

public

virtual UInt32 getFragmentCount( void );
Return Value

Returns the count of free fragments.

Discussion

This method returns a count of free fragments. Each fragment describes a non-contiguous free range - deallocations will merge contiguous fragments together.


getFreeCount


Totals the sizes of the free fragments.

public

virtual IORangeScalar getFreeCount( void );
Return Value

Returns the total of the free fragments sizes.

Discussion

This method returns the total of the sizes of the fragments on the free list.


init


Standard initializer for IORangeAllocator.

public

virtual bool init( IORangeScalar endOfRange, IORangeScalar defaultAlignment, UInt32 capacity, IOOptionBits options );
Parameters
endOfRange

If the free list is to contain an initial fragment, set endOfRange to the last offset in the range, ie. size - 1, to create a free fragment for the range zero to endOfRange inclusive. If zero is passed, the free list will be initialized empty, and can be populated with calls to the deallocate method.

defaultAlignment

If this parameter is non-zero it specifies a required alignment for all allocations, for example pass 256 to align allocations on 256 byte boundaries. Zero or one specify unaligned allocations.

capacity

Sets the initial size of the free list in number of noncontiguous fragments. This value is also used for the capacityIncrement.

options

Pass kLocking if the instance can be used by multiple threads.

Return Value

Returns true if the instance is successfully initialized, false on failure.

Discussion

This method initializes an IORangeAllocator and optionally sets the free list to contain one fragment, from zero to an endOfRange parameter. The capacity in terms of free fragments and locking options are set for the instance.


setFragmentCapacityIncrement


Sets the count of fragments the free list will increase by when full.

public

virtual void setFragmentCapacityIncrement( UInt32 count );
Parameters
count

The number of fragments to increment the capacity by when the free list is full.

Discussion

This method sets the number of extra fragments the free list will expand to when full. It defaults to the initial capacity.


withRange


Standard factory method for IORangeAllocator.

public

static IORangeAllocator * withRange( IORangeScalar endOfRange, IORangeScalar defaultAlignment = 0, UInt32 capacity = 0, IOOptionBits options = 0 );
Parameters
endOfRange

If the free list is to contain an initial fragment, set endOfRange to the last offset in the range, ie. size - 1, to create a free fragment for the range zero to endOfRange inclusive. If zero is passed the free list will be initialized empty, and can be populated with calls to the deallocate method.

defaultAlignment

If this parameter is non-zero it specifies a required alignment for all allocations, for example pass 256 to align allocations on 256 byte boundaries. Zero or one specify unaligned allocations.

capacity

Sets the initial size of the free list in number of non-contiguous fragments. This value is also used for the capacityIncrement.

options

Pass kLocking if the instance can be used by multiple threads.

Return Value

Returns the new IORangeAllocator instance, to be released by the caller, or zero on failure.

Discussion

This method allocates and initializes an IORangeAllocator and optionally sets the free list to contain one fragment, from zero to an endOfRange parameter. The capacity in terms of free fragments and locking options are set for the instance.


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.

 

Last Updated: 2008-12-19