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

#include <fixed_allocator_eastl.h>

Inheritance diagram for eastl::fixed_allocator_with_overflow:
Collaboration diagram for eastl::fixed_allocator_with_overflow:

List of all members.

Public Member Functions

 fixed_allocator_with_overflow (const char *pName=EASTL_FIXED_POOL_DEFAULT_NAME)
 fixed_allocator_with_overflow (const fixed_allocator_with_overflow &)
fixed_allocator_with_overflowoperator= (const fixed_allocator_with_overflow &x)
void init (void *pMemory, size_t memorySize, size_t nodeSize, size_t alignment, size_t alignmentOffset=0)
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 *pName)

Protected Attributes

EASTLAllocatorType mOverflowAllocator
void * mpPoolBegin
void * mpPoolEnd
eastl_size_t mnNodeSize

Detailed Description

fixed_allocator_with_overflow

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.

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.

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.

Example usage: typedef eastl::list<int, fixed_allocator_with_overflow> 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 287 of file fixed_allocator_eastl.h.


Constructor & Destructor Documentation

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

fixed_allocator_with_overflow

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

Definition at line 295 of file fixed_allocator_eastl.h.

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

fixed_allocator_with_overflow

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 309 of file fixed_allocator_eastl.h.


Member Function Documentation

fixed_allocator_with_overflow& eastl::fixed_allocator_with_overflow::operator= ( const fixed_allocator_with_overflow x) [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 321 of file fixed_allocator_eastl.h.

void eastl::fixed_allocator_with_overflow::init ( void *  pMemory,
size_t  memorySize,
size_t  nodeSize,
size_t  alignment,
size_t  alignmentOffset = 0 
) [inline]

init

Reimplemented from eastl::fixed_pool_base.

Definition at line 335 of file fixed_allocator_eastl.h.

void* eastl::fixed_allocator_with_overflow::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 351 of file fixed_allocator_eastl.h.

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

allocate

Definition at line 376 of file fixed_allocator_eastl.h.

void eastl::fixed_allocator_with_overflow::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 388 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