Class to handle allocation of multiple instances of the same class by blocks. It is useful to reduce the number of new calls that, when too high, might cause a performance bottleneck.
More...
#include <BlockAllocator.h>
|
size_t | blockSize |
| How many elements per allocated block.
|
|
vector< Class * > | blocks |
| Vector of allocated blocks. Each pointer in this vectors points to the starting element of a block of blockSize elements. More...
|
|
size_t | lastBlockElements |
| The number of already used elements in last block. More...
|
|
Class * | lastBlock |
| Pointer to last block in blocks. It is useful to prevent multiple queries for the same block at blocks vector. More...
|
|
std::function< size_t(void)> | _nextBlockSize |
| Compute the next block size. By default it preserves blockSize but it can be overridden to provide a dynamic behavior for block size.
|
|
|
class | boost::serialization::access |
|
template<class Class>
class BlockAllocator< Class >
Class to handle allocation of multiple instances of the same class by blocks. It is useful to reduce the number of new calls that, when too high, might cause a performance bottleneck.
- Author
- Alberto M. Esmoris Pena
- Version
- 1.0
- Template Parameters
-
Class | Type of class to be allocated |
◆ BlockAllocator()
Default constructor for BlockAllocator.
- Parameters
-
blockSize | The block size to be used for allocations |
◆ _new()
The allocation itself.
- Returns
- Allocated block
◆ getBlocks()
Obtain a vector with pointers to start of allocated blocks.
- Returns
- Vector with pointers to start of allocated blocks
◆ nextNew()
Obtain the next new allocated object.
If no block has been allocated, it handles the allocation of the first block. If last allocated block is not full, it return the next not yet used element in the block. If last allocated block is full, it allocates a new block
- Returns
- Next new allocated object
◆ serialize()
template<class Class >
template<class Archive >
void BlockAllocator< Class >::serialize |
( |
Archive & |
ar, |
|
|
const unsigned int |
version |
|
) |
| |
|
inlineprivate |
Serialize a BlockAllocator to a stream of byes.
- Template Parameters
-
- Parameters
-
ar | Specific rendering for the stream of bytes |
version | Version number for the BlockAllocator |
◆ setNextBlockSize()
template<class Class >
virtual void BlockAllocator< Class >::setNextBlockSize |
( |
std::function< size_t(void)> |
f | ) |
|
|
inlinevirtual |
◆ blocks
Vector of allocated blocks. Each pointer in this vectors points to the starting element of a block of blockSize elements.
- See also
- BlockAllocator::lastBlock
◆ lastBlock
◆ lastBlockElements
The documentation for this class was generated from the following file: