A pool allocator, implemented as a vector-based pair of linked lists.
More...
#include <vector_pool.h>
template<typename T>
class corgi::VectorPool< T >
A pool allocator, implemented as a vector-based pair of linked lists.
- Template Parameters
-
T | The data type of the data stored by the VectorPool. |
|
static const size_t | kOutOfBounds = static_cast<size_t>(-1) |
| A sentinel value that represents an out-of-bounds index.
|
|
static const UniqueIdType | kInvalidId = 0 |
| A sentinel value that represents an invalid ID. More...
|
|
static const size_t | kFirstUsed = 0 |
| Used to demarcate the first element of our used list. More...
|
|
static const size_t | kLastUsed = 1 |
| Used to demarcate the last element of our used list. More...
|
|
static const size_t | kFirstFree = 2 |
| Used to demarcate the first element of our free list. More...
|
|
static const size_t | kLastFree = 3 |
| Used to demarcate the last element of our free list. More...
|
|
static const size_t | kTotalReserved = 4 |
| Used to indicate the number of reserved elements. (e.g. kFirstUsed, kLastUsed, kFirstFree, kLastFree).
|
|
|
template<bool > |
class | IteratorTemplate |
|
class | VectorPoolReference |
|
Gets the total number of active elements.
- Returns
- A size_t representing the total number of active elements in the VectorPool.
Get an Iterator to the first active element in the VectorPool.
This is suitable for traversing all of the active elements in the VectorPool.
- Returns
- Returns an Iterator to the first active element in the VectorPool.
Gets a ConstIterator to the first active element in the VectorPool.
This is suitable for traversing all of the active elements in the VectorPool.
- Returns
- Returns a ConstIterator to the first active element in the VectorPool.
Gets a ConstIterator to the last active element in the VectorPool.
This is suitable as an end condition when iterating over all active elements in the VectorPool.
- Returns
- Returns a ConstIterator to the last active element in the VectorPool.
Gets an Iterator to the last active element in the VectorPool.
This is suitable as an end condition when iterating over all active elements in the VectorPool.
- Returns
- Returns An Iterator to the last active element in the VectorPool.
Frees an element at a given index.
- Note
- This removes the element from the list of active elements, and adds it to the front of the inactive list (to be used later, when we add elements to the VectorPool).
- Parameters
-
[in] | index | The index corresponding to the element that should be freed. |
Frees a given element.
- Note
- This removes the element from the list of active elements, and adds it to the front of the inactive list (to be used later, when we add elements to the VectorPool).
- Parameters
-
@ Frees an element that an Iterator points to.
- Note
- This removes the element from the list of active elements, and adds it to the front of the inactive list (to be used later, when we add elements to the VectorPool).
- Parameters
-
[in] | iter | An Iterator that references an element that should be freed. |
- Returns
- Returns an incremented Iterator that refers to the element immediately after the freed element.
Get the data at the given element index.
- Note
- The pointer is not guaranteed to remain valid, if the vector needs to relocate the data in memory. In general, if you need to hold on to a reference to a data element, it is recommended that you use a VectorPoolReference.
- Warning
- Asserts if the index is illegal (i.e. out of range for the underlying vector).
- Parameters
-
[in] | index | The index of the data element to return. |
- Returns
- Returns a pointer to the data.
Get the data at the given element index.
- Note
- The pointer is not guaranteed to remain valid, if the vector needs to relocate the data in memory. In general, if you need to hold on to a reference to a data element, it is recommended that you use a VectorPoolReference.
- Warning
- Asserts if the index is illegal (i.e. out of range for the underlying vector).
- Parameters
-
[in] | index | The index of the data element to return. |
- Returns
- Returns a const pointer to the data.
Get a VectorPoolReference to a new element.
- Note
- This function grabs the first free element (if one exists). Otherwise, it allocates a new one on the underlying vector.
- Parameters
-
[in] | alloc_location | An AllocationLocation enum determining whether to add to the front or back of the underlying vector. |
- Returns
- Returns a VectorPoolReference pointing to the new element.
Expands the vector until it is at least as large as new_size.
- Note
- : If the vector already contains at least new_size elements, then there is no effect.
- Parameters
-
[in] | new_size | A size_t indicating the new minimum size for the underlying vector. |
Get the total size of the vector pool.
This is the total number of allocated elements (used AND free) by the underlying vector.
- Returns
- A size_t representing the total size of the VectorPool (both used AND free elements).
Used to demarcate the first element of our free list.
- Note
- This is never given actual data. It is only used for list demarcation.
Used to demarcate the first element of our used list.
- Note
- This is never given actual data. It is only used for list demarcation.
A sentinel value that represents an invalid ID.
- Note
- Unique IDs start at 1.
Used to demarcate the last element of our free list.
- Note
- This is never given actual data. It is only used for list demarcation.
Used to demarcate the last element of our used list.
- Note
- This is never given actual data. It is only used for list demarcation.
The documentation for this class was generated from the following file: