#include <fixed_allocator.h>
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_overflow & | operator= (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) |
bool | can_allocate () const |
![]() | |
fixed_pool_base (void *pMemory=NULL) | |
fixed_pool_base & | operator= (const fixed_pool_base &) |
EASTL_API void | init (void *pMemory, size_t memorySize, size_t nodeSize, size_t alignment, size_t alignmentOffset=0) |
size_t | peak_size () const |
bool | can_allocate () const |
Protected Attributes | |
EASTLAllocatorType | mOverflowAllocator |
void * | mpPoolBegin |
void * | mpPoolEnd |
eastl_size_t | mnNodeSize |
Additional Inherited Members | |
![]() | |
Link * | mpHead |
Link * | mpNext |
Link * | mpCapacity |
size_t | mnNodeSize |
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));
|
inline |
Default constructor. The user usually will need to call init() after
constructing via this constructor.
|
inline |
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.
|
inline |
allocate
|
inline |
allocate
Allocates a new object of the size specified upon class initialization. Returns NULL if there is no more memory.
|
inline |
can_allocate
Returns true if there are any free links.
|
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.
|
inline |
init
|
inline |
operator=
By their nature, fixed-allocators cannot be copied in any useful way, as by their nature the user must manually initialize them.