Orxonox  0.0.5 Codename: Arcturus
Classes | Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
orxonox::SmallObjectAllocator Class Reference

This class is used to allocate and free small objects (usually not polymorphic). More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/util/SmallObjectAllocator.h>

Classes

struct  Chunk
 The memory chunk is at the same time an element of a single linked list. More...
 

Public Member Functions

 SmallObjectAllocator (size_t objectSize, size_t numObjects=64)
 Constructor: initializes the allocator and its values. More...
 
 ~SmallObjectAllocator ()
 Destructor: deletes the allocated memory blocks. More...
 
voidalloc ()
 Returns the first free memory chunk or allocates a new block of memory. More...
 
void free (void *chunk)
 Puts the memory chunk back on the list of free memory. More...
 

Static Private Member Functions

static voidgetNext (void *chunk)
 Helper function, returns the next_ pointer of a Chunk. More...
 
static void setNext (void *chunk, void *next)
 Helper function, used to set the next_ pointer of a Chunk. More...
 

Private Attributes

std::vector< char * > blocks_
 A list of all allocated memory blocks (used to destroy them again) More...
 
size_t chunkSize_
 The size of each chunk (and usually also the size of the created objects) More...
 
voidfirst_
 A pointer to the first free memory chunk. More...
 
size_t numChunksPerBlock_
 The number of chunks per memory block. More...
 

Detailed Description

This class is used to allocate and free small objects (usually not polymorphic).

SmallObjectAllocator provides a fast alternative to new and delete for small objects.

See also
See this description for more information and an example.

Constructor & Destructor Documentation

orxonox::SmallObjectAllocator::SmallObjectAllocator ( size_t  objectSize,
size_t  numObjects = 64 
)

Constructor: initializes the allocator and its values.

Parameters
objectSizeThe size in bytes (returned by sizeof()) of the allocated objects
numObjectsThe number of objects that are allocated in one block of memory
orxonox::SmallObjectAllocator::~SmallObjectAllocator ( )

Destructor: deletes the allocated memory blocks.

Member Function Documentation

void * orxonox::SmallObjectAllocator::alloc ( )

Returns the first free memory chunk or allocates a new block of memory.

void orxonox::SmallObjectAllocator::free ( void chunk)

Puts the memory chunk back on the list of free memory.

void * orxonox::SmallObjectAllocator::getNext ( void chunk)
staticprivate

Helper function, returns the next_ pointer of a Chunk.

void orxonox::SmallObjectAllocator::setNext ( void chunk,
void next 
)
staticprivate

Helper function, used to set the next_ pointer of a Chunk.

Member Data Documentation

std::vector<char*> orxonox::SmallObjectAllocator::blocks_
private

A list of all allocated memory blocks (used to destroy them again)

size_t orxonox::SmallObjectAllocator::chunkSize_
private

The size of each chunk (and usually also the size of the created objects)

void* orxonox::SmallObjectAllocator::first_
private

A pointer to the first free memory chunk.

size_t orxonox::SmallObjectAllocator::numChunksPerBlock_
private

The number of chunks per memory block.


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