Sierra Toolkit Version of the Day
eastl::fixed_allocator Class Reference

#include <fixed_allocator_eastl.h>

Inheritance diagram for eastl::fixed_allocator:
Collaboration diagram for eastl::fixed_allocator:

List of all members.

Public Member Functions

 fixed_allocator (const char *=EASTL_FIXED_POOL_DEFAULT_NAME)
 fixed_allocator (const fixed_allocator &)
fixed_allocatoroperator= (const fixed_allocator &)
void * allocate (size_t, int=0)
void * allocate (size_t n, size_t, size_t, int flags=0)
void deallocate (void *p, size_t)
const char * get_name () const
void set_name (const char *)

Detailed Description

fixed_allocator

Implements an allocator which allocates a single fixed size where the size, alignment, and memory used for the pool is defined at runtime by the user. This is different from fixed containers such as fixed_list whereby the size and alignment are determined at compile time and the memory is directly built into the container's member data.

If the pool's memory is exhausted or was never initialized, the allocate function returns NULL. Consider the fixed_allocator_with_overflow class as an alternative in order to deal with this situation.

This class requires the user to call container.get_allocator().init() after constructing the container. There currently isn't a way to construct the container with the initialization parameters, though with some effort such a thing could probably be made possible. It's not as simple as it might first seem, due to the non-copyable nature of fixed allocators. A side effect of this limitation is that you cannot copy-construct a container using fixed_allocators.

Another side-effect is that you cannot swap two containers using a fixed_allocator, as a swap requires temporary memory allocated by an equivalent allocator, and such a thing cannot be done implicitly. A workaround for the swap limitation is that you can implement your own swap whereby you provide an explicitly created temporary object.

Note: Be careful to set the allocator's node size to the size of the container node and not the size of the contained object. Note that the example code below uses IntListNode.

Example usage: typedef eastl::list<int, fixed_allocator> IntList; typedef IntList::node_type IntListNode;

IntListNode buffer[200]; IntList intList; intList.get_allocator().init(buffer, sizeof(buffer), sizeof(IntListNode), __alignof(IntListNode));

Definition at line 109 of file fixed_allocator_eastl.h.


Constructor & Destructor Documentation

eastl::fixed_allocator::fixed_allocator ( const char *  = EASTL_FIXED_POOL_DEFAULT_NAME) [inline]

fixed_allocator

Default constructor. The user usually will need to call init() after constructing via this constructor.

Definition at line 117 of file fixed_allocator_eastl.h.

eastl::fixed_allocator::fixed_allocator ( const fixed_allocator ) [inline]

fixed_allocator

Copy constructor. The user usually will need to call init() after constructing via this constructor. By their nature, fixed-allocators cannot be copied in any useful way, as by their nature the user must manually initialize them.

Definition at line 130 of file fixed_allocator_eastl.h.


Member Function Documentation

fixed_allocator& eastl::fixed_allocator::operator= ( const fixed_allocator ) [inline]

operator=

By their nature, fixed-allocators cannot be copied in any useful way, as by their nature the user must manually initialize them.

Definition at line 142 of file fixed_allocator_eastl.h.

void* eastl::fixed_allocator::allocate ( size_t  ,
int  = 0 
) [inline]

allocate

Allocates a new object of the size specified upon class initialization. Returns NULL if there is no more memory.

Definition at line 161 of file fixed_allocator_eastl.h.

void* eastl::fixed_allocator::allocate ( size_t  n,
size_t  ,
size_t  ,
int  flags = 0 
) [inline]

allocate

Definition at line 204 of file fixed_allocator_eastl.h.

void eastl::fixed_allocator::deallocate ( void *  p,
size_t   
) [inline]

deallocate

Frees the given object which was allocated by allocate(). If the given node was not allocated by allocate() then the behaviour is undefined.

Definition at line 216 of file fixed_allocator_eastl.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines