JASSv2
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
JASS::allocator_memory Class Reference

Memory allocator out of a single non-growable fixed-sized buffer. More...

#include <allocator_memory.h>

Inheritance diagram for JASS::allocator_memory:
JASS::allocator

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.
 
- Public Member Functions inherited from JASS::allocator
 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 Public Member Functions inherited from JASS::allocator
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.
 
- Protected Attributes inherited from JASS::allocator
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 Protected Attributes inherited from JASS::allocator
static constexpr size_t alignment_boundary = 1
 Elsewhere don't bother with alignment (align on byte boundaries)
 

Detailed Description

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.

Member Function Documentation

§ malloc()

void * JASS::allocator_memory::malloc ( size_t  bytes,
size_t  alignment = alignment_boundary 
)
virtual

Allocate a small chunk of memory from the internal pool and return a pointer to the caller.

Parameters
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*))
Returns
A pointer to a block of memory of size bytes, or NULL on failure.

Implements JASS::allocator.

§ operator!=()

virtual bool JASS::allocator_memory::operator!= ( const allocator with)
inlinevirtual

Compare for inequlity two objects of this class type.

Parameters
with[in] The object to compare to.
Returns
True if this != that, else false.

Implements JASS::allocator.

§ operator==()

virtual bool JASS::allocator_memory::operator== ( const allocator with)
inlinevirtual

Compare for equality two objects of this class type.

Parameters
with[in] The object to compare to.
Returns
True if this == that, else false.

Implements JASS::allocator.


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