aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
fixedAllocator.h
Go to the documentation of this file.
1
/****************************************************************************
2
* This file is part of the aGrUM/pyAgrum library. *
3
* *
4
* Copyright (c) 2005-2026 by *
5
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
6
* - Christophe GONZALES(_at_AMU) *
7
* *
8
* The aGrUM/pyAgrum library is free software; you can redistribute it *
9
* and/or modify it under the terms of either : *
10
* *
11
* - the GNU Lesser General Public License as published by *
12
* the Free Software Foundation, either version 3 of the License, *
13
* or (at your option) any later version, *
14
* - the MIT license (MIT), *
15
* - or both in dual license, as here. *
16
* *
17
* (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18
* *
19
* This aGrUM/pyAgrum library is distributed in the hope that it will be *
20
* useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26
* OTHER DEALINGS IN THE SOFTWARE. *
27
* *
28
* See LICENCES for more details. *
29
* *
30
* SPDX-FileCopyrightText: Copyright 2005-2026 *
31
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
32
* - Christophe GONZALES(_at_AMU) *
33
* SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34
* *
35
* Contact : info_at_agrum_dot_org *
36
* homepage : http://agrum.gitlab.io *
37
* gitlab : https://gitlab.com/agrumery/agrum *
38
* *
39
****************************************************************************/
40
41
50
#ifndef GUM_FIXED_ALLOCATOR_H
51
#define GUM_FIXED_ALLOCATOR_H
52
53
// ============================================================================
54
#include <mutex>
55
#include <thread>
56
// ============================================================================
57
#include <
agrum/agrum.h
>
58
59
// ============================================================================
60
61
namespace
gum
{
78
79
class
GUM_SHARED_PUBLIC
FixedAllocator
{
80
// clang-format off
96
// clang-format on
97
98
struct
_Chunk_
{
99
// ============================================================================
101
// ============================================================================
102
void
_init_
(
const
std::size_t& blockSize,
const
unsigned
char
& numBlocks);
103
104
// ============================================================================
106
// ============================================================================
107
void
*
_allocate_
(
const
std::size_t& blockSize);
108
109
// ============================================================================
111
// ============================================================================
112
void
_deallocat_
(
void
* p,
const
std::size_t& blockSize);
113
114
// ============================================================================
116
// ============================================================================
117
void
_release_
();
118
119
// ============================================================================
121
// ============================================================================
122
unsigned
char
*
_pData_
;
123
124
// ============================================================================
126
// ============================================================================
127
unsigned
char
_firstAvailableBlock_
;
128
129
// ============================================================================
131
// ============================================================================
132
unsigned
char
_blocksAvailable_
;
133
};
134
135
public
:
136
// ############################################################################
138
// ############################################################################
140
141
// ============================================================================
149
// ============================================================================
150
FixedAllocator
(
const
std::size_t& blockSize,
const
unsigned
char
& numBlocks = UCHAR_MAX);
151
152
// ============================================================================
154
// ============================================================================
155
~FixedAllocator
();
156
158
159
// ############################################################################
161
// ############################################################################
163
164
// ============================================================================
166
// ============================================================================
167
void
*
allocate
();
168
169
// ============================================================================
171
// ============================================================================
172
void
deallocate
(
void
* pDeallocatedBlock);
173
175
176
// ============================================================================
178
// ============================================================================
179
const
size_t
&
objectSize
();
180
181
private
:
182
// ============================================================================
184
// ============================================================================
185
std::size_t
_blockSize_
;
186
187
// ============================================================================
189
// ============================================================================
190
unsigned
char
_numBlocks_
;
191
192
// ============================================================================
194
// ============================================================================
195
using
_Chunks_
= std::vector< _Chunk_ >;
196
_Chunks_
_chunks_
;
197
198
// ============================================================================
200
// ============================================================================
201
_Chunks_::iterator
_allocChunk_
;
202
203
// ============================================================================
205
// ============================================================================
206
_Chunks_::iterator
_deallocChunk_
;
207
};
208
209
}
// namespace gum
210
211
#ifndef GUM_NO_INLINE
212
# include <
agrum/base/core/smallobjectallocator/fixedAllocator_inl.h
>
213
#endif
214
215
#endif
// FIXEDALLOCATOR_H
agrum.h
gum::FixedAllocator::_chunks_
_Chunks_ _chunks_
Definition
fixedAllocator.h:196
gum::FixedAllocator::FixedAllocator
FixedAllocator(const std::size_t &blockSize, const unsigned char &numBlocks=UCHAR_MAX)
Constructor.
Definition
fixedAllocator_inl.h:83
gum::FixedAllocator::_deallocChunk_
_Chunks_::iterator _deallocChunk_
Last Chunk used for a deallocation.
Definition
fixedAllocator.h:206
gum::FixedAllocator::deallocate
void deallocate(void *pDeallocatedBlock)
Deallocates a block.
Definition
fixedAllocator.cpp:157
gum::FixedAllocator::_numBlocks_
unsigned char _numBlocks_
The maximum number of blocks a chunk can allocate.
Definition
fixedAllocator.h:190
gum::FixedAllocator::_blockSize_
std::size_t _blockSize_
Size of a memory block allocated.
Definition
fixedAllocator.h:185
gum::FixedAllocator::_Chunks_
std::vector< _Chunk_ > _Chunks_
Vector of Chunk objects.
Definition
fixedAllocator.h:195
gum::FixedAllocator::_allocChunk_
_Chunks_::iterator _allocChunk_
Last Chunk used for an allocation.
Definition
fixedAllocator.h:201
gum::FixedAllocator::objectSize
const size_t & objectSize()
Returns the size of block allocated by this FixedAllocator.
Definition
fixedAllocator_inl.h:118
gum::FixedAllocator::allocate
void * allocate()
Allocates a block.
Definition
fixedAllocator.cpp:131
fixedAllocator_inl.h
Inlines of gum::FixedAllocator.
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
gum::FixedAllocator::_Chunk_
Allocates objects of one given size.
Definition
fixedAllocator.h:98
gum::FixedAllocator::_Chunk_::_firstAvailableBlock_
unsigned char _firstAvailableBlock_
Holds the index of the first block available in this chunck.
Definition
fixedAllocator.h:127
gum::FixedAllocator::_Chunk_::_deallocat_
void _deallocat_(void *p, const std::size_t &blockSize)
Deallocates a block of memory.
Definition
fixedAllocator.cpp:107
gum::FixedAllocator::_Chunk_::_pData_
unsigned char * _pData_
Pointer to the managed memory itself.
Definition
fixedAllocator.h:122
gum::FixedAllocator::_Chunk_::_allocate_
void * _allocate_(const std::size_t &blockSize)
Allocates a block of memory.
Definition
fixedAllocator.cpp:83
gum::FixedAllocator::_Chunk_::_init_
void _init_(const std::size_t &blockSize, const unsigned char &numBlocks)
Initializes a Chunk object.
Definition
fixedAllocator.cpp:59
gum::FixedAllocator::_Chunk_::_release_
void _release_()
Releases the allocated memory.
Definition
fixedAllocator_inl.h:74
gum::FixedAllocator::_Chunk_::_blocksAvailable_
unsigned char _blocksAvailable_
Number of blocks available in this chunck.
Definition
fixedAllocator.h:132
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0