LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
|
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 |
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 () |
bool | hasUsers () const |
Returns whether there are currently users. More... | |
Counter_t | Count () const |
Returns the number of registered users. 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 29 of file BulkAllocator.h.
|
private |
Definition at line 321 of file BulkAllocator.h.
|
inherited |
type of user counter
Definition at line 229 of file BulkAllocator.h.
|
private |
Definition at line 322 of file BulkAllocator.h.
|
private |
Definition at line 381 of file BulkAllocator.h.
typedef T* lar::details::bulk_allocator::BulkAllocatorBase< T >::pointer |
Definition at line 269 of file BulkAllocator.h.
typedef size_t lar::details::bulk_allocator::BulkAllocatorBase< T >::size_type |
Definition at line 267 of file BulkAllocator.h.
typedef T lar::details::bulk_allocator::BulkAllocatorBase< T >::value_type |
Definition at line 268 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.
References lar::details::bulk_allocator::BulkAllocatorBase< T >::ChunkSize, lar::details::bulk_allocator::BulkAllocatorBase< T >::GetChunkSize(), and lar::details::bulk_allocator::BulkAllocatorBase< T >::Preallocate().
|
inline |
Destructor: releases all the memory pool (.
Definition at line 275 of file BulkAllocator.h.
|
inline |
Add a new pool user with the current parameters.
Definition at line 287 of file BulkAllocator.h.
References lar::details::bulk_allocator::ReferenceCounter::AddUser().
Referenced by lar::details::bulk_allocator::BulkAllocatorBase< T >::AddUser().
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 451 of file BulkAllocator.h.
References lar::details::bulk_allocator::BulkAllocatorBase< T >::AddUser(), lar::details::bulk_allocator::BulkAllocatorBase< T >::ChunkSize, lar::details::bulk_allocator::BulkAllocatorBase< T >::Preallocate(), and lar::details::bulk_allocator::BulkAllocatorBase< T >::SetChunkSize().
BulkAllocatorBase< T >::size_type lar::details::bulk_allocator::BulkAllocatorBase< T >::AllocatedCount | ( | ) | const |
Returns the total number of entries in the pool.
Definition at line 466 of file BulkAllocator.h.
References lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryPool, and n.
Referenced by lar::details::bulk_allocator::BulkAllocatorBase< T >::Free().
|
inlineinherited |
Returns the number of registered users.
Definition at line 235 of file BulkAllocator.h.
References util::counter().
void lar::details::bulk_allocator::BulkAllocatorBase< T >::Free | ( | ) |
Releases the pool of memory; all pointer to it become invalid.
Definition at line 432 of file BulkAllocator.h.
References lar::details::bulk_allocator::BulkAllocatorBase< T >::AllocatedCount(), lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryPool, and lar::details::bulk_allocator::BulkAllocatorBase< T >::NChunks().
Referenced by lar::details::bulk_allocator::BulkAllocatorBase< T >::RemoveUser().
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 511 of file BulkAllocator.h.
References lar::details::bulk_allocator::BulkAllocatorBase< T >::allocator, lar::details::bulk_allocator::BulkAllocatorBase< T >::ChunkSize, lar::details::bulk_allocator::BulkAllocatorBase< T >::GetCounts(), and lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryPool.
|
inline |
Returns the current chunk size.
Definition at line 314 of file BulkAllocator.h.
Referenced by lar::details::bulk_allocator::BulkAllocatorBase< T >::BulkAllocatorBase(), and lar::details::bulk_allocator::BulkAllocatorBase< T >::SetChunkSize().
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 484 of file BulkAllocator.h.
References lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryPool.
Referenced by lar::details::bulk_allocator::BulkAllocatorBase< T >::Get().
|
inlineinherited |
Returns whether there are currently users.
Definition at line 232 of file BulkAllocator.h.
References util::counter().
Referenced by lar::details::bulk_allocator::BulkAllocatorBase< T >::RemoveUser().
|
inline |
Returns the number of memory pool chunks allocated.
Definition at line 305 of file BulkAllocator.h.
Referenced by lar::details::bulk_allocator::BulkAllocatorBase< T >::Free().
|
inline |
Preallocates a chunk of the current ChunkSize;
Definition at line 318 of file BulkAllocator.h.
References lar::details::bulk_allocator::BulkAllocatorBase< T >::Preallocate().
Referenced by lar::details::bulk_allocator::BulkAllocatorBase< T >::AddUser(), lar::details::bulk_allocator::BulkAllocatorBase< T >::BulkAllocatorBase(), and lar::details::bulk_allocator::BulkAllocatorBase< T >::Preallocate().
|
private |
Preallocates a chunk of the given size; allocates if free space < n.
Definition at line 459 of file BulkAllocator.h.
References lar::details::bulk_allocator::BulkAllocatorBase< T >::allocator, lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryPool, and n.
|
inline |
Releases memory pointed by the specified pointer (but it does not).
Definition at line 284 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 442 of file BulkAllocator.h.
References lar::details::bulk_allocator::BulkAllocatorBase< T >::Free(), lar::details::bulk_allocator::ReferenceCounter::hasUsers(), and lar::details::bulk_allocator::ReferenceCounter::RemoveUser().
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 498 of file BulkAllocator.h.
References lar::details::bulk_allocator::BulkAllocatorBase< T >::ChunkSize, and lar::details::bulk_allocator::BulkAllocatorBase< T >::GetChunkSize().
Referenced by lar::details::bulk_allocator::BulkAllocatorBase< T >::AddUser().
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 475 of file BulkAllocator.h.
References lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryPool, and n.
|
private |
the actual allocator we use
Definition at line 324 of file BulkAllocator.h.
Referenced by lar::details::bulk_allocator::BulkAllocatorBase< T >::Get(), and lar::details::bulk_allocator::BulkAllocatorBase< T >::Preallocate().
|
private |
size of the chunks to add
Definition at line 383 of file BulkAllocator.h.
Referenced by lar::details::bulk_allocator::BulkAllocatorBase< T >::AddUser(), lar::details::bulk_allocator::BulkAllocatorBase< T >::BulkAllocatorBase(), lar::details::bulk_allocator::BulkAllocatorBase< T >::Get(), and lar::details::bulk_allocator::BulkAllocatorBase< T >::SetChunkSize().
|
staticprivate |
Default chunk size (default: 10000)
Definition at line 387 of file BulkAllocator.h.
|
private |
list of all memory chunks; first is free
Definition at line 384 of file BulkAllocator.h.
Referenced by lar::details::bulk_allocator::BulkAllocatorBase< T >::AllocatedCount(), lar::details::bulk_allocator::BulkAllocatorBase< T >::Free(), lar::details::bulk_allocator::BulkAllocatorBase< T >::Get(), lar::details::bulk_allocator::BulkAllocatorBase< T >::GetCounts(), lar::details::bulk_allocator::BulkAllocatorBase< T >::Preallocate(), and lar::details::bulk_allocator::BulkAllocatorBase< T >::UsedCount().