aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
smallObjectAllocator.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 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-2025 *
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_SMALL_OBJECT_ALLOCATOR_H
51#define GUM_SMALL_OBJECT_ALLOCATOR_H
52
53// ============================================================================
54#include <agrum/agrum.h>
55// ============================================================================
58
59// ============================================================================
60
61
62namespace gum {
77 public:
83 static const size_t GUM_DEFAULT_CHUNK_SIZE;
84
90 static const size_t GUM_DEFAULT_MAX_OBJECT_SIZE;
91
92
93 // ############################################################################
95 // ############################################################################
97
98 private:
99 // ============================================================================
104 // ============================================================================
106
107 // ============================================================================
109 // ============================================================================
111
112 // ============================================================================
114 // ============================================================================
116
117 public:
118 // ============================================================================
120 // ============================================================================
121 virtual ~SmallObjectAllocator();
122
124
126
127 // ############################################################################
129 // ############################################################################
131 // ============================================================================
133 // ============================================================================
134 void* allocate(const size_t& objectSize);
135
136 // ============================================================================
141 // ============================================================================
142 void deallocate(void* pDeallocatedObject, const size_t& objectSize);
143
145
146 // ============================================================================
148 // ============================================================================
150 GUM_TRACE("Nb Small Allocation : " << nbAllocation
151 << " - Nb Small Deallocation : " << nbDeallocation);
152 }
153
155
157
158 private:
159 // ============================================================================
161 // ============================================================================
163
165
166 // ============================================================================
168 // ============================================================================
169 std::size_t _chunkSize_;
170
171 // ============================================================================
173 // ============================================================================
174 std::size_t _maxObjectSize_;
175
178 };
179} // namespace gum
180
181// Macro used to shorten code in classes using SmallObjectAllocator
182#define SOA_ALLOCATE(x) SmallObjectAllocator::instance().allocate(x)
183#define SOA_DEALLOCATE(x, y) SmallObjectAllocator::instance().deallocate(x, y)
184
185#ifndef GUM_NO_INLINE
187#endif
188
189#endif // GUM_SMALL_OBJECT_ALLOCATOR_H
The class for generic Hash Tables.
Definition hashTable.h:637
<agrum/base/core/smallObjectAllocator.h>
HashTable< Size, FixedAllocator * > _Pool_
The pool containing FixedAllocator.
static SmallObjectAllocator & instance()
SmallObjectAllocator & operator=(const SmallObjectAllocator &)
Operator = (does nothing since we use a Singleton).
void displayStats()
Displays the number of allocation and deallocation made so far.
void * allocate(const size_t &objectSize)
Allocates a block.
static const size_t GUM_DEFAULT_CHUNK_SIZE
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
static const size_t GUM_DEFAULT_MAX_OBJECT_SIZE
std::size_t _maxObjectSize_
The maximal size of an object befor new is called.
virtual ~SmallObjectAllocator()
Destructor.
std::size_t _chunkSize_
The memory that a chunk allocates.
SmallObjectAllocator(const SmallObjectAllocator &)
Copy Constructor (does nothing since we use a Singleton).
Headers of gum::FixedAllocator.
Size Idx
Type for indexes.
Definition types.h:79
Class hash tables iterators.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Inlines of gum::SmallObjectAllocator.