![]() |
aGrUM 3.1.1
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 chunk 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 accommodate 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 195 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 83 of file fixedAllocator_inl.h.
References _allocChunk_, _blockSize_, _chunks_, _deallocChunk_, and _numBlocks_.
| INLINE gum::FixedAllocator::~FixedAllocator | ( | ) |
Destructor.
Definition at line 95 of file fixedAllocator_inl.h.
References _chunks_.
| void * gum::FixedAllocator::allocate | ( | ) |
Allocates a block.
Definition at line 131 of file fixedAllocator.cpp.
References _allocChunk_, _blockSize_, _chunks_, _deallocChunk_, gum::FixedAllocator::_Chunk_::_init_(), and _numBlocks_.
| void gum::FixedAllocator::deallocate | ( | void * | pDeallocatedBlock | ) |
Deallocates a block.
Definition at line 157 of file fixedAllocator.cpp.
References _blockSize_, _chunks_, _deallocChunk_, and _numBlocks_.
| INLINE const size_t & gum::FixedAllocator::objectSize | ( | ) |
Returns the size of block allocated by this FixedAllocator.
Definition at line 118 of file fixedAllocator_inl.h.
References _blockSize_.
|
private |
Last Chunk used for an allocation.
Definition at line 201 of file fixedAllocator.h.
Referenced by FixedAllocator(), and allocate().
|
private |
Size of a memory block allocated.
Definition at line 185 of file fixedAllocator.h.
Referenced by FixedAllocator(), allocate(), deallocate(), and objectSize().
|
private |
Definition at line 196 of file fixedAllocator.h.
Referenced by FixedAllocator(), ~FixedAllocator(), allocate(), and deallocate().
|
private |
Last Chunk used for a deallocation.
Definition at line 206 of file fixedAllocator.h.
Referenced by FixedAllocator(), allocate(), and deallocate().
|
private |
The maximum number of blocks a chunk can allocate.
Definition at line 190 of file fixedAllocator.h.
Referenced by FixedAllocator(), allocate(), and deallocate().