FreeNOS
|
#include <Allocator.h>
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... | |
Allocator * | parent () |
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 Allocator * | getDefault () |
Retrieve the currently default Allocator. More... | |
Protected Member Functions | |
Address | aligned (const Address addr, const Size boundary) const |
Align memory address. More... | |
Private Attributes | |
Allocator * | m_parent |
Our parent Allocator, if any. More... | |
Range | m_range |
Range of memory that this Allocator manages. More... | |
Static Private Attributes | |
static Allocator * | m_default = ZERO |
Points to the default Allocator for new()/delete(). More... | |
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.
typedef struct Allocator::Range Allocator::Range |
Describes a range of memory.
enum Allocator::Result |
Allocation results.
Enumerator | |
---|---|
Success | |
InvalidAddress | |
InvalidSize | |
InvalidAlignment | |
OutOfMemory |
Definition at line 53 of file Allocator.h.
Allocator::Allocator | ( | ) |
Default class constructor.
Definition at line 25 of file Allocator.cpp.
References m_range, and MemoryBlock::set().
Allocator::Allocator | ( | const Range | range | ) |
Class constructor with Range input.
range | Block of continguous memory to manage. |
Definition at line 31 of file Allocator.cpp.
References Allocator::Range::alignment, assert, m_range, and Allocator::Range::size.
|
virtual |
Class destructor.
Definition at line 40 of file Allocator.cpp.
Align memory address.
Any alignment corrections on the input address will result in an address which is higher than the input address.
addr | Input address which need to be aligned. |
boundary | Boundary size to align the address for. |
Definition at line 94 of file Allocator.cpp.
Referenced by BubbleAllocator::allocate(), PageAllocator::allocate(), PoolAllocator::allocate(), and PoolAllocator::allocatePool().
Size Allocator::alignment | ( | ) | const |
Get memory alignment in bytes for allocations.
Definition at line 74 of file Allocator.cpp.
References Allocator::Range::alignment, and m_range.
Referenced by BubbleAllocator::allocate(), and BitAllocator::allocateFrom().
|
virtual |
Allocate memory.
range | Contains the requested size and alignment on input. On output, contains the actual allocated address. |
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[]().
|
virtual |
Get memory available.
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().
Address Allocator::base | ( | ) | const |
Get memory base address for allocations.
Definition at line 69 of file Allocator.cpp.
References Allocator::Range::address, and m_range.
Referenced by BubbleAllocator::allocate(), PageAllocator::allocate(), BitAllocator::allocateAt(), BitAllocator::allocateFrom(), BitAllocator::isAllocated(), BitAllocator::release(), IntelPageDirectory::releasePhysical(), ARMFirstTable::releasePhysical(), SplitAllocator::toPhysical(), and SplitAllocator::toVirtual().
|
static |
Retrieve the currently default Allocator.
Definition at line 54 of file Allocator.cpp.
References m_default.
Referenced by operator delete(), operator delete[](), operator new(), and operator new[]().
Allocator * Allocator::parent | ( | ) |
Get parent Allocator.
Definition at line 49 of file Allocator.cpp.
References m_parent.
Referenced by PoolAllocator::allocatePool(), PoolAllocator::PoolAllocator(), PoolAllocator::releasePool(), and setParent().
|
virtual |
Release memory.
addr | Points to memory previously returned by 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().
|
static |
Makes the given Allocator the default.
alloc | Instance of an Allocator. |
Definition at line 59 of file Allocator.cpp.
References m_default.
Referenced by Kernel::initializeHeap(), and setupHeap().
void Allocator::setParent | ( | Allocator * | parent | ) |
Set parent allocator.
parent | New parent allocator. |
Definition at line 44 of file Allocator.cpp.
References m_parent, and parent().
Referenced by PoolAllocator::PoolAllocator().
|
virtual |
Get memory size.
Reimplemented in PoolAllocator.
Definition at line 64 of file Allocator.cpp.
References m_range, and Allocator::Range::size.
Referenced by BubbleAllocator::allocate(), BubbleAllocator::available(), PageAllocator::available(), BitAllocator::isAllocated(), IntelPageDirectory::releasePhysical(), ARMFirstTable::releasePhysical(), and SystemInfoHandler().
Points to the default Allocator for new()/delete().
Definition at line 186 of file Allocator.h.
Referenced by getDefault(), and setDefault().
|
private |
Our parent Allocator, if any.
Definition at line 189 of file Allocator.h.
Referenced by available(), parent(), and setParent().
|
private |
Range of memory that this Allocator manages.
Definition at line 192 of file Allocator.h.
Referenced by alignment(), Allocator(), base(), and size().