Panda3D
|
An implementation of a very simple block allocator. More...
#include "simpleAllocator.h"
Public Member Functions | |
SimpleAllocator (size_t max_size, Mutex &lock) | |
SimpleAllocatorBlock * | alloc (size_t size) |
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 (ostream &out) const |
void | set_max_size (size_t max_size) |
Changes the available space for allocated objects. More... | |
void | write (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 33 of file simpleAllocator.h.
|
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 41 of file simpleAllocator.I.
References is_empty().
Referenced by get_first_block().
|
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 104 of file simpleAllocator.I.
References get_first_block().
Referenced by set_max_size().
|
inline |
Returns a pointer to the first allocated block, or NULL if there are no allocated blocks.
Definition at line 116 of file simpleAllocator.I.
References alloc(), and SimpleAllocatorBlock::~SimpleAllocatorBlock().
Referenced by get_contiguous(), and VertexDataPage::get_first_block().
|
inline |
Returns the available space for allocated objects.
Definition at line 75 of file simpleAllocator.I.
References set_max_size().
Referenced by get_total_size().
|
inline |
Returns the total size of allocated objects.
Definition at line 64 of file simpleAllocator.I.
References get_max_size().
Referenced by VertexDataSaveFile::get_used_file_size(), and is_empty().
|
inline |
Returns true if there are no blocks allocated on this page, or false if there is at least one.
Definition at line 53 of file simpleAllocator.I.
References get_total_size().
Referenced by alloc().
|
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 88 of file simpleAllocator.I.
References get_contiguous().
Referenced by get_max_size().