FreeNOS
Public Member Functions | Private Attributes
BitAllocator Class Reference

Bit memory allocator. More...

#include <BitAllocator.h>

Inheritance diagram for BitAllocator:
Allocator PoolAllocator::Pool

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...
 
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...
 

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 AllocatorgetDefault ()
 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...
 

Detailed Description

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 & Destructor Documentation

◆ BitAllocator()

BitAllocator::BitAllocator ( const Range  range,
const Size  chunkSize,
u8 bitmap = ZERO 
)

Constructor function.

Parameters
rangeBlock of continguous memory to manage.
chunkSizeThe input memory range will be divided into equally sized chunks. The chunkSize must be greater than zero.
bitmapPointer to existing bitmap array or ZERO to allocate new.

Definition at line 21 of file BitAllocator.cpp.

Member Function Documentation

◆ allocate()

Allocator::Result BitAllocator::allocate ( Allocator::Range args)
virtual

Allocate memory.

Parameters
argsContains 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.
Returns
Result value.

Reimplemented from Allocator.

Definition at line 41 of file BitAllocator.cpp.

References allocateFrom(), m_lastBit, and Allocator::OutOfMemory.

Referenced by SplitAllocator::allocate().

◆ allocateAt()

Allocator::Result BitAllocator::allocateAt ( const Address  addr)

Allocate a specific address.

Parameters
addrAllocate a specific address.
Returns
Result value.

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().

◆ allocateFrom()

Allocator::Result BitAllocator::allocateFrom ( Allocator::Range args,
const Size  startBit 
)

Allocate memory from defined starting address.

Parameters
argsContains 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.
startBitBit position in the bitmap array to start searching at.
Returns
Result value.

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().

◆ available()

Size BitAllocator::available ( ) const
virtual

Get available memory.

Returns
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().

◆ chunkSize()

Size BitAllocator::chunkSize ( ) const

Get chunk size.

Returns
Chunk size.

Definition at line 31 of file BitAllocator.cpp.

References m_chunkSize.

◆ isAllocated()

bool BitAllocator::isAllocated ( const Address  page) const

Check if a chunk is allocated.

Returns
True if allocated, false otherwise.

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().

◆ release()

Allocator::Result BitAllocator::release ( const Address  chunk)
virtual

Release memory chunk.

Parameters
chunkThe memory chunk to release.
Returns
Result value.

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().

Field Documentation

◆ m_array

BitArray BitAllocator::m_array
private

Marks which chunks are (un)used.

Definition at line 120 of file BitAllocator.h.

Referenced by allocateAt(), allocateFrom(), available(), isAllocated(), and release().

◆ m_chunkSize

const Size BitAllocator::m_chunkSize
private

Size of each chunk.

Definition at line 123 of file BitAllocator.h.

Referenced by allocateAt(), allocateFrom(), available(), chunkSize(), isAllocated(), and release().

◆ m_lastBit

Size BitAllocator::m_lastBit
private

Last bit that was set.

Definition at line 126 of file BitAllocator.h.

Referenced by allocate(), and allocateFrom().


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