JASSv2
|
Memory allocator out of a single non-growable fixed-sized buffer. More...
#include <allocator_memory.h>
Public Member Functions | |
allocator_memory (void *buffer, size_t length) | |
Constructor. | |
virtual | ~allocator_memory () |
Destructor. | |
virtual bool | operator== (const allocator &with) |
Compare for equality two objects of this class type. More... | |
virtual bool | operator!= (const allocator &with) |
Compare for inequlity two objects of this class type. More... | |
virtual void * | malloc (size_t bytes, size_t alignment=alignment_boundary) |
Allocate a small chunk of memory from the internal pool and return a pointer to the caller. More... | |
virtual void | rewind (void) |
Throw away (without calling delete) all objects allocated in the memory space of this allocator Delete is not called for any objects allocated in this space, the memory is simply re-claimed. | |
![]() | |
allocator () | |
Constructor. | |
virtual | ~allocator () |
Destructor. | |
size_t | capacity (void) const |
Return the amount of memory that this object has allocated to it. More... | |
size_t | size (void) const |
Return the number of bytes of memory this object has handed back to callers. More... | |
Static Public Member Functions | |
static void | unittest (void) |
Unit test this class. | |
![]() | |
static size_t | realign (const void *address, size_t boundary) |
Compute the number of extra bytes of memory necessary for an allocation to start on an aligned boundary. More... | |
Protected Attributes | |
std::atomic< uint8_t * > | buffer |
The buffer we're allocating from. | |
![]() | |
std::atomic< size_t > | used |
The number of bytes this object has passed back to the caller. | |
std::atomic< size_t > | allocated |
The number of bytes this object has allocated. | |
Additional Inherited Members | |
![]() | |
static constexpr size_t | alignment_boundary = 1 |
Elsewhere don't bother with alignment (align on byte boundaries) | |
Memory allocator out of a single non-growable fixed-sized buffer.
This allocator is thread safe. A single allocator can be called from multiple threads concurrently and they will each return a valid pointer to a piece of memory that is not overlapping with any pointer returned from any other call and is of the requested size.
|
virtual |
Allocate a small chunk of memory from the internal pool and return a pointer to the caller.
bytes | [in] The size of the chunk of memory. |
alignment | [in] If a word-aligned piece of memory is needed then this is the word-size (e.g. sizeof(void*)) |
Implements JASS::allocator.
|
inlinevirtual |
Compare for inequlity two objects of this class type.
with | [in] The object to compare to. |
Implements JASS::allocator.
|
inlinevirtual |
Compare for equality two objects of this class type.
with | [in] The object to compare to. |
Implements JASS::allocator.