aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
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-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_SMALL_OBJECT_ALLOCATOR_H
51
#define GUM_SMALL_OBJECT_ALLOCATOR_H
52
53
// ============================================================================
54
#include <
agrum/agrum.h
>
55
// ============================================================================
56
#include <
agrum/base/core/hashTable.h
>
57
#include <
agrum/base/core/smallobjectallocator/fixedAllocator.h
>
58
59
// ============================================================================
60
61
62
namespace
gum
{
76
class
GUM_SHARED_PUBLIC
SmallObjectAllocator
{
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
// ============================================================================
105
SmallObjectAllocator
();
106
107
// ============================================================================
109
// ============================================================================
110
SmallObjectAllocator
(
const
SmallObjectAllocator
&) =
delete
;
111
112
// ============================================================================
114
// ============================================================================
115
SmallObjectAllocator
&
operator=
(
const
SmallObjectAllocator
&);
116
117
public
:
118
// ============================================================================
120
// ============================================================================
121
virtual
~SmallObjectAllocator
();
122
124
125
static
SmallObjectAllocator
&
instance
();
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
// ============================================================================
149
void
displayStats
();
150
151
Idx
nbAlloc
();
152
153
Idx
nbDealloc
();
154
155
private
:
156
// ============================================================================
158
// ============================================================================
159
using
_Pool_
=
HashTable< Size, FixedAllocator* >
;
160
161
_Pool_
_pool_
;
162
163
// ============================================================================
165
// ============================================================================
166
std::size_t
_chunkSize_
;
167
168
// ============================================================================
170
// ============================================================================
171
std::size_t
_maxObjectSize_
;
172
173
// protects the critical sections
174
std::mutex
_mutex_
;
175
176
Idx
nbAllocation
;
177
Idx
nbDeallocation
;
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
186
# include <
agrum/base/core/smallobjectallocator/smallObjectAllocator_inl.h
>
187
#endif
188
189
#endif
// GUM_SMALL_OBJECT_ALLOCATOR_H
agrum.h
gum::HashTable
The class for generic Hash Tables.
Definition
hashTable.h:640
gum::SmallObjectAllocator::_Pool_
HashTable< Size, FixedAllocator * > _Pool_
The pool containing FixedAllocator.
Definition
smallObjectAllocator.h:159
gum::SmallObjectAllocator::instance
static SmallObjectAllocator & instance()
Definition
smallObjectAllocator_inl.h:96
gum::SmallObjectAllocator::_mutex_
std::mutex _mutex_
Definition
smallObjectAllocator.h:174
gum::SmallObjectAllocator::displayStats
void displayStats()
Displays the number of allocation and deallocation made so far.
Definition
smallObjectAllocator_inl.h:137
gum::SmallObjectAllocator::operator=
SmallObjectAllocator & operator=(const SmallObjectAllocator &)
Operator = (does nothing since we use a Singleton).
Definition
smallObjectAllocator_inl.h:133
gum::SmallObjectAllocator::nbAlloc
Idx nbAlloc()
Definition
smallObjectAllocator_inl.h:142
gum::SmallObjectAllocator::nbAllocation
Idx nbAllocation
Definition
smallObjectAllocator.h:176
gum::SmallObjectAllocator::allocate
void * allocate(const size_t &objectSize)
Allocates a block.
Definition
smallObjectAllocator.cpp:72
gum::SmallObjectAllocator::GUM_DEFAULT_CHUNK_SIZE
static const size_t GUM_DEFAULT_CHUNK_SIZE
Definition
smallObjectAllocator.h:83
gum::SmallObjectAllocator::nbDealloc
Idx nbDealloc()
Definition
smallObjectAllocator_inl.h:144
gum::SmallObjectAllocator::SmallObjectAllocator
SmallObjectAllocator()
Constructor.
Definition
smallObjectAllocator_inl.h:73
gum::SmallObjectAllocator::_pool_
_Pool_ _pool_
Definition
smallObjectAllocator.h:161
gum::SmallObjectAllocator::nbDeallocation
Idx nbDeallocation
Definition
smallObjectAllocator.h:177
gum::SmallObjectAllocator::deallocate
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
Definition
smallObjectAllocator_inl.h:116
gum::SmallObjectAllocator::GUM_DEFAULT_MAX_OBJECT_SIZE
static const size_t GUM_DEFAULT_MAX_OBJECT_SIZE
Definition
smallObjectAllocator.h:90
gum::SmallObjectAllocator::_maxObjectSize_
std::size_t _maxObjectSize_
The maximal size of an object befor new is called.
Definition
smallObjectAllocator.h:171
gum::SmallObjectAllocator::_chunkSize_
std::size_t _chunkSize_
The memory that a chunk allocates.
Definition
smallObjectAllocator.h:166
gum::SmallObjectAllocator::SmallObjectAllocator
SmallObjectAllocator(const SmallObjectAllocator &)=delete
Copy Constructor (does nothing since we use a Singleton).
fixedAllocator.h
Headers of gum::FixedAllocator.
gum::Idx
Size Idx
Type for indexes.
Definition
types.h:79
hashTable.h
Class hash tables iterators.
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
smallObjectAllocator_inl.h
Inlines of gum::SmallObjectAllocator.
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0