|
Open Model Railroad Network (OpenMRN)
|
An arena allocator, which is optimized to not be able to free individual entries, only the entire allocator. More...
#include <ForwardAllocator.hxx>
Public Member Functions | |
| void * | allocate (size_t size, size_t align) |
| Allocates a block of memory. | |
Public Attributes | |
| size_t | allocSize_ {0} |
| Total number of bytes allocated. | |
| size_t | allocWasted_ {0} |
| Number of bytes lost due to alignment and end-of-block chunks. | |
Static Public Attributes | |
| static constexpr size_t | BLOCK_BYTE_SIZE = 1024 |
| Allocated blocks will be this size. | |
Private Types | |
| typedef uint64_t | primitive_t |
| A primitive type that has sufficient alignment to what we support. | |
| typedef primitive_t | AlignedPayload[BLOCK_BYTE_SIZE/sizeof(primitive_t)] |
| An array type with the BLOCK_BYTE_SIZE size. | |
| typedef Buffer< AlignedPayload > | BufferType |
| Buffer type that we will be allocating from the pool. | |
Private Member Functions | |
| uint8_t * | head_ptr () |
Private Attributes | |
| TypedQueue< BufferType > | allocatedBlocks_ |
| Holds all blocks that we allocated (ever). | |
| size_t | offsetInLast_ {BLOCK_BYTE_SIZE + 1} |
| Points into the last allocated block to the next emtpy space. | |
| OSMutex | lock_ |
| Lock that protects the offset in last variable and the queue of blocks. | |
Static Private Attributes | |
| static DynamicPool * | kbytePool_ |
| This buffer pool will have one bucket to allocate 1kb objects each and kep them on a free list. | |
An arena allocator, which is optimized to not be able to free individual entries, only the entire allocator.
Integrated with a buffer pool to reuse large blocks of heap memory without being exposed to heap fragmentation.
Definition at line 51 of file ForwardAllocator.hxx.
|
private |
An array type with the BLOCK_BYTE_SIZE size.
Definition at line 74 of file ForwardAllocator.hxx.
|
private |
Buffer type that we will be allocating from the pool.
Definition at line 78 of file ForwardAllocator.hxx.
|
private |
A primitive type that has sufficient alignment to what we support.
Definition at line 72 of file ForwardAllocator.hxx.
| ForwardAllocator::ForwardAllocator | ( | ) |
Definition at line 56 of file ForwardAllocator.cxx.
| ForwardAllocator::~ForwardAllocator | ( | ) |
Definition at line 60 of file ForwardAllocator.cxx.
| void * ForwardAllocator::allocate | ( | size_t | size, |
| size_t | align | ||
| ) |
Allocates a block of memory.
Thread-safe.
| size | the number of bytes to allocate. |
| align | alignment of allocated object in bytes (1 to 8). |
Definition at line 69 of file ForwardAllocator.cxx.
|
inlineprivate |
Definition at line 83 of file ForwardAllocator.hxx.
|
private |
Holds all blocks that we allocated (ever).
They will all be freed in the destructor.
Definition at line 94 of file ForwardAllocator.hxx.
| size_t ForwardAllocator::allocSize_ {0} |
Total number of bytes allocated.
Definition at line 100 of file ForwardAllocator.hxx.
| size_t ForwardAllocator::allocWasted_ {0} |
Number of bytes lost due to alignment and end-of-block chunks.
Definition at line 102 of file ForwardAllocator.hxx.
|
staticconstexpr |
Allocated blocks will be this size.
Definition at line 55 of file ForwardAllocator.hxx.
|
staticprivate |
This buffer pool will have one bucket to allocate 1kb objects each and kep them on a free list.
The freelist is shared between different allocators.
Definition at line 110 of file ForwardAllocator.hxx.
|
private |
Lock that protects the offset in last variable and the queue of blocks.
Definition at line 106 of file ForwardAllocator.hxx.
|
private |
Points into the last allocated block to the next emtpy space.
Definition at line 96 of file ForwardAllocator.hxx.