A class managing a memory pool. More...
#include <BulkAllocator.h>
Classes | |
class | MemoryChunk_t |
Internal memory chunk; like a std::vector, but does not construct. More... | |
Public Types | |
typedef size_t | size_type |
typedef T | value_type |
typedef T * | pointer |
Public Types inherited from lar::details::bulk_allocator::ReferenceCounter | |
typedef unsigned int | Counter_t |
type of user counter More... | |
Public Member Functions | |
BulkAllocatorBase (size_type NewChunkSize=DefaultChunkSize, bool bPreallocate=false) | |
Constructor; preallocates memory if explicitly requested. More... | |
~BulkAllocatorBase () | |
Destructor: releases all the memory pool (. More... | |
void | Free () |
Releases the pool of memory; all pointer to it become invalid. More... | |
pointer | Get (size_type n) |
Returns a pointer to memory for n new values of type T. More... | |
void | Release (pointer) |
Releases memory pointed by the specified pointer (but it does not). More... | |
void | AddUser () |
Add a new pool user with the current parameters. More... | |
void | AddUser (size_type NewChunkSize, bool bPreallocate=false) |
Add a new pool user with new parameters. More... | |
bool | RemoveUser () |
Removed a user to the users count; if no user is left, free the pool. More... | |
size_type | AllocatedCount () const |
Returns the total number of entries in the pool. More... | |
size_type | UsedCount () const |
Returns the total number of used entries in the pool. More... | |
size_type | FreeCount () const |
Returns the total number of unused entries in the pool. More... | |
size_type | NChunks () const |
Returns the number of memory pool chunks allocated. More... | |
std::array< size_type, 2 > | GetCounts () const |
Returns an array equivalent to { UsedCount(), FreeCount() }. More... | |
void | SetChunkSize (size_type NewChunkSize, bool force=false) |
Sets the chunk size for the future allocations. More... | |
size_type | GetChunkSize () const |
Returns the current chunk size. More... | |
void | Preallocate () |
Public Member Functions inherited from lar::details::bulk_allocator::ReferenceCounter | |
bool | hasUsers () const |
Returns whether there are currently users. More... | |
Counter_t | Count () const |
Returns the number of registered users. More... | |
void | AddUser () |
Adds a user to the users count. More... | |
bool | RemoveUser () |
Removed a user to the users count; returns false if no user yet. More... | |
Private Types | |
typedef std::allocator< T > | Allocator_t |
typedef Allocator_t::difference_type | difference_type |
typedef std::vector< MemoryChunk_t > | MemoryPool_t |
Private Member Functions | |
void | Preallocate (size_type n) |
Preallocates a chunk of the given size; allocates if free space < n. More... | |
Private Attributes | |
Allocator_t | allocator |
the actual allocator we use More... | |
size_type | ChunkSize |
size of the chunks to add More... | |
MemoryPool_t | MemoryPool |
list of all memory chunks; first is free More... | |
Static Private Attributes | |
static size_type | DefaultChunkSize = 10000 |
Default chunk size (default: 10000) More... | |
A class managing a memory pool.
The management policy is to allocate big chunks of memory. Memory is never freed, until the last user is removed (which is responsibility of the caller), this object is destroyed of Free() is explicitly called. The amount of memory on
This class has a users counter. The count must be explicitly handled by the caller.
Definition at line 31 of file BulkAllocator.h.
|
private |
Definition at line 318 of file BulkAllocator.h.
|
private |
Definition at line 319 of file BulkAllocator.h.
|
private |
Definition at line 378 of file BulkAllocator.h.
typedef T* lar::details::bulk_allocator::BulkAllocatorBase< T >::pointer |
Definition at line 264 of file BulkAllocator.h.
typedef size_t lar::details::bulk_allocator::BulkAllocatorBase< T >::size_type |
Definition at line 262 of file BulkAllocator.h.
typedef T lar::details::bulk_allocator::BulkAllocatorBase< T >::value_type |
Definition at line 263 of file BulkAllocator.h.
lar::details::bulk_allocator::BulkAllocatorBase< T >::BulkAllocatorBase | ( | size_type | NewChunkSize = DefaultChunkSize , |
bool | bPreallocate = false |
||
) |
Constructor; preallocates memory if explicitly requested.
Definition at line 418 of file BulkAllocator.h.
|
inline |
Destructor: releases all the memory pool (.
Definition at line 272 of file BulkAllocator.h.
|
inline |
Add a new pool user with the current parameters.
Definition at line 284 of file BulkAllocator.h.
void lar::details::bulk_allocator::BulkAllocatorBase< T >::AddUser | ( | size_type | NewChunkSize, |
bool | bPreallocate = false |
||
) |
Add a new pool user with new parameters.
Definition at line 455 of file BulkAllocator.h.
BulkAllocatorBase< T >::size_type lar::details::bulk_allocator::BulkAllocatorBase< T >::AllocatedCount | ( | ) | const |
Returns the total number of entries in the pool.
Definition at line 472 of file BulkAllocator.h.
void lar::details::bulk_allocator::BulkAllocatorBase< T >::Free | ( | ) |
Releases the pool of memory; all pointer to it become invalid.
Definition at line 434 of file BulkAllocator.h.
size_type lar::details::bulk_allocator::BulkAllocatorBase< T >::FreeCount | ( | ) | const |
Returns the total number of unused entries in the pool.
|
inline |
Returns a pointer to memory for n new values of type T.
Definition at line 523 of file BulkAllocator.h.
|
inline |
Returns the current chunk size.
Definition at line 311 of file BulkAllocator.h.
std::array< typename BulkAllocatorBase< T >::size_type, 2 > lar::details::bulk_allocator::BulkAllocatorBase< T >::GetCounts | ( | ) | const |
Returns an array equivalent to { UsedCount(), FreeCount() }.
Definition at line 492 of file BulkAllocator.h.
|
inline |
Returns the number of memory pool chunks allocated.
Definition at line 302 of file BulkAllocator.h.
|
inline |
Preallocates a chunk of the current ChunkSize;
Definition at line 315 of file BulkAllocator.h.
|
private |
Preallocates a chunk of the given size; allocates if free space < n.
Definition at line 464 of file BulkAllocator.h.
|
inline |
Releases memory pointed by the specified pointer (but it does not).
Definition at line 281 of file BulkAllocator.h.
bool lar::details::bulk_allocator::BulkAllocatorBase< T >::RemoveUser | ( | ) |
Removed a user to the users count; if no user is left, free the pool.
Definition at line 445 of file BulkAllocator.h.
void lar::details::bulk_allocator::BulkAllocatorBase< T >::SetChunkSize | ( | size_type | NewChunkSize, |
bool | force = false |
||
) |
Sets the chunk size for the future allocations.
Definition at line 507 of file BulkAllocator.h.
BulkAllocatorBase< T >::size_type lar::details::bulk_allocator::BulkAllocatorBase< T >::UsedCount | ( | ) | const |
Returns the total number of used entries in the pool.
Definition at line 482 of file BulkAllocator.h.
|
private |
the actual allocator we use
Definition at line 321 of file BulkAllocator.h.
|
private |
size of the chunks to add
Definition at line 380 of file BulkAllocator.h.
|
staticprivate |
Default chunk size (default: 10000)
Definition at line 384 of file BulkAllocator.h.
|
private |
list of all memory chunks; first is free
Definition at line 381 of file BulkAllocator.h.