![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
Allocates objects of one given size. More...
#include <agrum/base/core/fixedAllocator.h>
Classes | |
| struct | _Chunk_ |
| Allocates objects of one given size. More... | |
Public Member Functions | |
| const size_t & | objectSize () |
| Returns the size of block allocated by this FixedAllocator. | |
Constructors / Destructors | |
| FixedAllocator (const std::size_t &blockSize, const unsigned char &numBlocks=UCHAR_MAX) | |
| Constructor. | |
| ~FixedAllocator () | |
| Destructor. | |
Allocator / Deallocator | |
| void * | allocate () |
| Allocates a block. | |
| void | deallocate (void *pDeallocatedBlock) |
| Deallocates a block. | |
Private Types | |
| using | _Chunks_ = std::vector< _Chunk_ > |
| Vector of Chunk objects. | |
Private Attributes | |
| std::size_t | _blockSize_ |
| Size of a memory block allocated. | |
| unsigned char | _numBlocks_ |
| The maximum number of blocks a chunk can allocate. | |
| _Chunks_ | _chunks_ |
| _Chunks_::iterator | _allocChunk_ |
| Last Chunk used for an allocation. | |
| _Chunks_::iterator | _deallocChunk_ |
| Last Chunk used for a deallocation. | |
Allocates objects of one given size.
Fixed allocator knows how to allocate and deallocate blocks of fixed size but is not limited to a chunck size. Its capacity is limited only by the available memory. To achieve this, FixedAllocator aggregates a vector of Chunk objects. Whenever an allocation request occurs, FixedAllocators looks for a Chunk that can accomodate the request. If all Chunks are filled up, FixedAllocator appends a new Chunk.
Definition at line 79 of file fixedAllocator.h.
|
private |
Vector of Chunk objects.
Definition at line 199 of file fixedAllocator.h.
| INLINE gum::FixedAllocator::FixedAllocator | ( | const std::size_t & | blockSize, |
| const unsigned char & | numBlocks = UCHAR_MAX ) |
Constructor.
| blockSize | is the size of an allocated block. |
| numBlocks | is the number of block allocated per chunk numBlock * blockSize is the size that a chunk allocates directly when it is created |
Definition at line 150 of file fixedAllocator_inl.h.
References _allocChunk_, _blockSize_, _chunks_, _deallocChunk_, and _numBlocks_.
| INLINE gum::FixedAllocator::~FixedAllocator | ( | ) |
Destructor.
Definition at line 162 of file fixedAllocator_inl.h.
References _chunks_.
| INLINE void * gum::FixedAllocator::allocate | ( | ) |
Allocates a block.
Definition at line 175 of file fixedAllocator_inl.h.
References _allocChunk_, _blockSize_, _chunks_, _deallocChunk_, gum::FixedAllocator::_Chunk_::_init_(), and _numBlocks_.
| INLINE void gum::FixedAllocator::deallocate | ( | void * | pDeallocatedBlock | ) |
Deallocates a block.
Definition at line 204 of file fixedAllocator_inl.h.
References _blockSize_, _chunks_, _deallocChunk_, and _numBlocks_.
|
inline |
Returns the size of block allocated by this FixedAllocator.
Definition at line 183 of file fixedAllocator.h.
References _blockSize_.
|
private |
Last Chunk used for an allocation.
Definition at line 205 of file fixedAllocator.h.
Referenced by FixedAllocator(), and allocate().
|
private |
Size of a memory block allocated.
Definition at line 189 of file fixedAllocator.h.
Referenced by FixedAllocator(), allocate(), deallocate(), and objectSize().
|
private |
Definition at line 200 of file fixedAllocator.h.
Referenced by FixedAllocator(), ~FixedAllocator(), allocate(), and deallocate().
|
private |
Last Chunk used for a deallocation.
Definition at line 210 of file fixedAllocator.h.
Referenced by FixedAllocator(), allocate(), and deallocate().
|
private |
The maximum number of blocks a chunk can allocate.
Definition at line 194 of file fixedAllocator.h.
Referenced by FixedAllocator(), allocate(), and deallocate().