|
FreeNOS
|
Bit memory allocator. More...
#include <BitAllocator.h>
Public Member Functions | |
| BitAllocator (const Range range, const Size chunkSize, u8 *bitmap=ZERO) | |
| Constructor function. More... | |
| Size | chunkSize () const |
| Get chunk size. More... | |
| virtual Size | available () const |
| Get available memory. More... | |
| virtual Result | allocate (Range &args) |
| Allocate memory. More... | |
| Result | allocateFrom (Range &args, const Size startBit) |
| Allocate memory from defined starting address. More... | |
| Result | allocateAt (const Address addr) |
| Allocate a specific address. More... | |
| bool | isAllocated (const Address page) const |
| Check if a chunk is allocated. More... | |
| virtual Result | release (const Address chunk) |
| Release memory chunk. More... | |
Public Member Functions inherited from Allocator | |
| 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... | |
Private Attributes | |
| BitArray | m_array |
| Marks which chunks are (un)used. More... | |
| const Size | m_chunkSize |
| Size of each chunk. More... | |
| Size | m_lastBit |
| Last bit that was set. More... | |
Additional Inherited Members | |
Public Types inherited from Allocator | |
| enum | Result { Success = 0, InvalidAddress, InvalidSize, InvalidAlignment, OutOfMemory } |
| Allocation results. More... | |
| typedef struct Allocator::Range | Range |
| Describes a range of memory. More... | |
Static Public Member Functions inherited from Allocator | |
| static void | setDefault (Allocator *alloc) |
| Makes the given Allocator the default. More... | |
| static Allocator * | getDefault () |
| Retrieve the currently default Allocator. More... | |
Protected Member Functions inherited from Allocator | |
| Address | aligned (const Address addr, const Size boundary) const |
| Align memory address. More... | |
Bit memory allocator.
Allocates memory by using a BitArray. All memory is divided in same sized parts called chunks. 1 in the BitArray means the chunk is used, 0 means unused.
Definition at line 40 of file BitAllocator.h.
Constructor function.
| range | Block of continguous memory to manage. |
| chunkSize | The input memory range will be divided into equally sized chunks. The chunkSize must be greater than zero. |
| bitmap | Pointer to existing bitmap array or ZERO to allocate new. |
Definition at line 21 of file BitAllocator.cpp.
|
virtual |
Allocate memory.
| args | Contains the requested size and alignment on input. The alignment value must be a multiple of the chunk size. On output, contains the actual allocated address. |
Reimplemented from Allocator.
Definition at line 41 of file BitAllocator.cpp.
References allocateFrom(), m_lastBit, and Allocator::OutOfMemory.
Referenced by SplitAllocator::allocate().
| Allocator::Result BitAllocator::allocateAt | ( | const Address | addr | ) |
Allocate a specific address.
| addr | Allocate a specific address. |
Definition at line 80 of file BitAllocator.cpp.
References assert, Allocator::base(), isAllocated(), m_array, m_chunkSize, BitArray::set(), and Allocator::Success.
Referenced by SplitAllocator::allocate().
| Allocator::Result BitAllocator::allocateFrom | ( | Allocator::Range & | args, |
| const Size | startBit | ||
| ) |
Allocate memory from defined starting address.
| args | Contains the requested size and alignment on input. The alignment value must be a multiple of the chunk size. On output, contains the actual allocated address. |
| startBit | Bit position in the bitmap array to start searching at. |
Definition at line 52 of file BitAllocator.cpp.
References Allocator::Range::address, Allocator::Range::alignment, Allocator::alignment(), assert, Allocator::base(), Allocator::InvalidAlignment, isAllocated(), m_array, m_chunkSize, m_lastBit, Allocator::OutOfMemory, BitArray::setNext(), Allocator::Range::size, BitArray::Success, and Allocator::Success.
Referenced by allocate().
|
virtual |
Get available memory.
Reimplemented from Allocator.
Definition at line 36 of file BitAllocator.cpp.
References BitArray::count(), m_array, and m_chunkSize.
Referenced by SplitAllocator::allocateSparse(), SplitAllocator::available(), and PoolAllocator::retrievePool().
| Size BitAllocator::chunkSize | ( | ) | const |
Get chunk size.
Definition at line 31 of file BitAllocator.cpp.
References m_chunkSize.
| bool BitAllocator::isAllocated | ( | const Address | page | ) | const |
Check if a chunk is allocated.
Definition at line 88 of file BitAllocator.cpp.
References assert, Allocator::base(), BitArray::isSet(), m_array, m_chunkSize, and Allocator::size().
Referenced by allocateAt(), allocateFrom(), SplitAllocator::isAllocated(), and release().
|
virtual |
Release memory chunk.
| chunk | The memory chunk to release. |
Reimplemented from Allocator.
Definition at line 97 of file BitAllocator.cpp.
References assert, Allocator::base(), isAllocated(), m_array, m_chunkSize, Allocator::Success, and BitArray::unset().
Referenced by SplitAllocator::release().
|
private |
Marks which chunks are (un)used.
Definition at line 120 of file BitAllocator.h.
Referenced by allocateAt(), allocateFrom(), available(), isAllocated(), and release().
|
private |
Size of each chunk.
Definition at line 123 of file BitAllocator.h.
Referenced by allocateAt(), allocateFrom(), available(), chunkSize(), isAllocated(), and release().
|
private |
Last bit that was set.
Definition at line 126 of file BitAllocator.h.
Referenced by allocate(), and allocateFrom().
1.8.17