Mac Developer Library

Developer

IORangeAllocator Class Reference

Options
Deployment Target:

On This Page
Language:

IORangeAllocator

Inheritance


  • IORangeAllocator

Conforms To


Not Applicable

Import Statement


Not Applicable

Objective-C

@import Kernel;

Availability


Available in OS X v10.0 and later.

A utility class to manage allocations from a range.

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.

  • Allocates from the free list, at any offset.

    Declaration

    C++

    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.

  • Allocates from the free list, at a set offset.

    Declaration

    C++

    virtual bool allocateRange( IORangeScalarstart, IORangeScalarsize );

    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.

  • Deallocates a range to the free list.

    Declaration

    C++

    virtual void deallocate( IORangeScalarstart, IORangeScalarsize );

    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.

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

    Declaration

    C++

    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.

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

    Declaration

    C++

    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.

  • Totals the sizes of the free fragments.

    Declaration

    C++

    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.

  • Standard initializer for IORangeAllocator.

    Declaration

    C++

    virtual bool init( IORangeScalarendOfRange, IORangeScalardefaultAlignment, UInt32capacity, IOOptionBitsoptions );

    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.

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

    Declaration

    C++

    virtual void setFragmentCapacityIncrement( UInt32count );

    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.

  • Standard factory method for IORangeAllocator.

    Declaration

    C++

    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.