FreeNOS
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes
Allocator Class Reference

Memory Allocator. More...

#include <Allocator.h>

Inheritance diagram for Allocator:
BitAllocator BubbleAllocator PageAllocator PoolAllocator SplitAllocator PoolAllocator::Pool

Data Structures

struct  Range
 Describes a range of memory. More...
 

Public Types

enum  Result {
  Success = 0, InvalidAddress, InvalidSize, InvalidAlignment,
  OutOfMemory
}
 Allocation results. More...
 
typedef struct Allocator::Range Range
 Describes a range of memory. More...
 

Public Member Functions

 Allocator ()
 Default class constructor. More...
 
 Allocator (const Range range)
 Class constructor with Range input. More...
 
virtual ~Allocator ()
 Class destructor. More...
 
void setParent (Allocator *parent)
 Set parent allocator. More...
 
Allocatorparent ()
 Get parent Allocator. More...
 
Address base () const
 Get memory base address for allocations. More...
 
Size alignment () const
 Get memory alignment in bytes for allocations. More...
 
virtual Size size () const
 Get memory size. More...
 
virtual Size available () const
 Get memory available. More...
 
virtual Result allocate (Range &range)
 Allocate memory. More...
 
virtual Result release (const Address addr)
 Release memory. More...
 

Static Public Member Functions

static void setDefault (Allocator *alloc)
 Makes the given Allocator the default. More...
 
static AllocatorgetDefault ()
 Retrieve the currently default Allocator. More...
 

Protected Member Functions

Address aligned (const Address addr, const Size boundary) const
 Align memory address. More...
 

Private Attributes

Allocatorm_parent
 Our parent Allocator, if any. More...
 
Range m_range
 Range of memory that this Allocator manages. More...
 

Static Private Attributes

static Allocatorm_default = ZERO
 Points to the default Allocator for new()/delete(). More...
 

Detailed Description

Memory Allocator.

This class defines an abstract memory allocator. Each class which derives must provide functions for memory allocation and release. The memory allocators form a hierarcy of parent-child. A parent allocator can provide memory to a child allocator. If a child allocator runs out of memory, it can ask the parent for more memory.

Definition at line 46 of file Allocator.h.

Member Typedef Documentation

◆ Range

Describes a range of memory.

Member Enumeration Documentation

◆ Result

Allocation results.

Enumerator
Success 
InvalidAddress 
InvalidSize 
InvalidAlignment 
OutOfMemory 

Definition at line 53 of file Allocator.h.

Constructor & Destructor Documentation

◆ Allocator() [1/2]

Allocator::Allocator ( )

Default class constructor.

Definition at line 25 of file Allocator.cpp.

References m_range, and MemoryBlock::set().

◆ Allocator() [2/2]

Allocator::Allocator ( const Range  range)

Class constructor with Range input.

Parameters
rangeBlock of continguous memory to manage.

Definition at line 31 of file Allocator.cpp.

References Allocator::Range::alignment, assert, m_range, and Allocator::Range::size.

◆ ~Allocator()

Allocator::~Allocator ( )
virtual

Class destructor.

Definition at line 40 of file Allocator.cpp.

Member Function Documentation

◆ aligned()

Address Allocator::aligned ( const Address  addr,
const Size  boundary 
) const
protected

Align memory address.

Any alignment corrections on the input address will result in an address which is higher than the input address.

Parameters
addrInput address which need to be aligned.
boundaryBoundary size to align the address for.
Returns
Aligned Address.

Definition at line 94 of file Allocator.cpp.

Referenced by BubbleAllocator::allocate(), PageAllocator::allocate(), PoolAllocator::allocate(), and PoolAllocator::allocatePool().

◆ alignment()

Size Allocator::alignment ( ) const

Get memory alignment in bytes for allocations.

Returns
Memory alignment value in bytes

Definition at line 74 of file Allocator.cpp.

References Allocator::Range::alignment, and m_range.

Referenced by BubbleAllocator::allocate(), and BitAllocator::allocateFrom().

◆ allocate()

Allocator::Result Allocator::allocate ( Allocator::Range range)
virtual

Allocate memory.

Parameters
rangeContains the requested size and alignment on input. On output, contains the actual allocated address.
Returns
Result value.

Reimplemented in PoolAllocator, BitAllocator, SplitAllocator, PageAllocator, and BubbleAllocator.

Definition at line 84 of file Allocator.cpp.

References OutOfMemory.

Referenced by PoolAllocator::allocatePool(), operator new(), and operator new[]().

◆ available()

Size Allocator::available ( ) const
virtual

Get memory available.

Returns
Size of memory available by the Allocator.

Reimplemented in PoolAllocator, BitAllocator, SplitAllocator, PageAllocator, and BubbleAllocator.

Definition at line 79 of file Allocator.cpp.

References available(), m_parent, and ZERO.

Referenced by available().

◆ base()

Address Allocator::base ( ) const

◆ getDefault()

Allocator * Allocator::getDefault ( )
static

Retrieve the currently default Allocator.

Returns
Allocator pointer.

Definition at line 54 of file Allocator.cpp.

References m_default.

Referenced by operator delete(), operator delete[](), operator new(), and operator new[]().

◆ parent()

Allocator * Allocator::parent ( )

Get parent Allocator.

Returns
Pointer to parent Allocator instance or NULL if none.

Definition at line 49 of file Allocator.cpp.

References m_parent.

Referenced by PoolAllocator::allocatePool(), PoolAllocator::PoolAllocator(), PoolAllocator::releasePool(), and setParent().

◆ release()

Allocator::Result Allocator::release ( const Address  addr)
virtual

Release memory.

Parameters
addrPoints to memory previously returned by allocate().
Returns
Result value.
See also
allocate

Reimplemented in BitAllocator, PoolAllocator, SplitAllocator, PageAllocator, and BubbleAllocator.

Definition at line 89 of file Allocator.cpp.

References InvalidAddress.

Referenced by operator delete(), operator delete[](), PoolAllocator::releasePool(), and ProcessShares::releaseShare().

◆ setDefault()

void Allocator::setDefault ( Allocator alloc)
static

Makes the given Allocator the default.

Parameters
allocInstance of an Allocator.

Definition at line 59 of file Allocator.cpp.

References m_default.

Referenced by Kernel::initializeHeap(), and setupHeap().

◆ setParent()

void Allocator::setParent ( Allocator parent)

Set parent allocator.

Parameters
parentNew parent allocator.

Definition at line 44 of file Allocator.cpp.

References m_parent, and parent().

Referenced by PoolAllocator::PoolAllocator().

◆ size()

Size Allocator::size ( ) const
virtual

Field Documentation

◆ m_default

Allocator * Allocator::m_default = ZERO
staticprivate

Points to the default Allocator for new()/delete().

Definition at line 186 of file Allocator.h.

Referenced by getDefault(), and setDefault().

◆ m_parent

Allocator* Allocator::m_parent
private

Our parent Allocator, if any.

Definition at line 189 of file Allocator.h.

Referenced by available(), parent(), and setParent().

◆ m_range

Range Allocator::m_range
private

Range of memory that this Allocator manages.

Definition at line 192 of file Allocator.h.

Referenced by alignment(), Allocator(), base(), and size().


The documentation for this class was generated from the following files: