An implementation of a very simple block allocator. More...
#include "simpleAllocator.h"
Public Member Functions | |
SimpleAllocator (size_t max_size, Mutex &lock) | |
SimpleAllocator (SimpleAllocator &&from) noexcept | |
Move constructor. More... | |
SimpleAllocatorBlock * | alloc (size_t size, size_t alignment=1) |
Allocates a new block. More... | |
size_t | get_contiguous () const |
Returns an upper-bound estimate of the size of the largest contiguous block that may be allocated. More... | |
SimpleAllocatorBlock * | get_first_block () const |
Returns a pointer to the first allocated block, or NULL if there are no allocated blocks. More... | |
size_t | get_max_size () const |
Returns the available space for allocated objects. More... | |
size_t | get_total_size () const |
Returns the total size of allocated objects. More... | |
bool | is_empty () const |
Returns true if there are no blocks allocated on this page, or false if there is at least one. More... | |
void | output (std::ostream &out) const |
void | set_max_size (size_t max_size) |
Changes the available space for allocated objects. More... | |
void | write (std::ostream &out) const |
Friends | |
class | SimpleAllocatorBlock |
An implementation of a very simple block allocator.
This class can allocate ranges of nonnegative integers within a specified upper limit; it uses a simple first-fit algorithm to find the next available space.
Definition at line 29 of file simpleAllocator.h.
|
noexcept |
Move constructor.
Definition at line 20 of file simpleAllocator.cxx.
|
inline |
Allocates a new block.
Returns NULL if a block of the requested size cannot be allocated.
To free the allocated block, call block->free(), or simply delete the block pointer.
Definition at line 35 of file simpleAllocator.I.
|
inline |
Returns an upper-bound estimate of the size of the largest contiguous block that may be allocated.
It is guaranteed that an attempt to allocate a block larger than this will fail, though it is not guaranteed that an attempt to allocate a block this size or smaller will succeed.
Definition at line 86 of file simpleAllocator.I.
|
inline |
Returns a pointer to the first allocated block, or NULL if there are no allocated blocks.
Definition at line 96 of file simpleAllocator.I.
Referenced by VertexDataPage::get_first_block().
|
inline |
Returns the available space for allocated objects.
Definition at line 63 of file simpleAllocator.I.
|
inline |
Returns the total size of allocated objects.
Definition at line 54 of file simpleAllocator.I.
Referenced by VertexDataSaveFile::get_used_file_size().
|
inline |
Returns true if there are no blocks allocated on this page, or false if there is at least one.
Definition at line 45 of file simpleAllocator.I.
|
inline |
Changes the available space for allocated objects.
This will not affect any already-allocated objects, but will have an effect on future calls to alloc().
Definition at line 74 of file simpleAllocator.I.