aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
fixedAllocator_inl.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
#pragma once
42
43
52
// ============================================================================
53
#include <
agrum/base/core/smallobjectallocator/fixedAllocator.h
>
54
55
// ============================================================================
56
57
namespace
gum
{
58
59
// ============================================================================
60
// Initializes a Chunk object
61
// ============================================================================
62
63
// ============================================================================
64
// Allocates a block of memory
65
// ============================================================================
66
67
// ============================================================================
68
// Deallocates a block of memory
69
// ============================================================================
70
71
// ============================================================================
72
// Releases the allocated memory
73
// ============================================================================
74
INLINE
void
FixedAllocator::_Chunk_::_release_
() {
delete
[]
_pData_
; }
75
76
// ############################################################################
77
// @name Constructors / Destructors
78
// ############################################################################
79
80
// ============================================================================
81
// Constructor.
82
// ============================================================================
83
INLINE
FixedAllocator::FixedAllocator
(
const
std::size_t& blockSize,
84
const
unsigned
char
& numBlocks) {
85
// GUM_CONSTRUCTOR(FixedAllocator);
86
_blockSize_
= blockSize;
87
_numBlocks_
= numBlocks;
88
_allocChunk_
=
_chunks_
.begin();
89
_deallocChunk_
=
_chunks_
.begin();
90
}
91
92
// ============================================================================
93
// Destructor.
94
// ============================================================================
95
INLINE
FixedAllocator::~FixedAllocator
() {
96
for
(_Chunks_::iterator chunkIter =
_chunks_
.begin(); chunkIter !=
_chunks_
.end();
97
++chunkIter) {
98
chunkIter->_release_();
99
}
100
// GUM_DESTRUCTOR(FixedAllocator);
101
}
102
103
// ############################################################################
104
// @name Allocator / Deallocator
105
// ############################################################################
106
107
// ============================================================================
108
// Allocates a block
109
// ============================================================================
110
111
// ============================================================================
112
// Deallocates a block
113
// ============================================================================
114
115
// ============================================================================
116
// Returns the size of block allocated by this FixedAllocator
117
// ============================================================================
118
INLINE
const
size_t
&
FixedAllocator::objectSize
() {
return
_blockSize_
; }
119
120
}
// namespace gum
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::_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::~FixedAllocator
~FixedAllocator()
Destructor.
Definition
fixedAllocator_inl.h:95
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
fixedAllocator.h
Headers of gum::FixedAllocator.
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
gum::FixedAllocator::_Chunk_::_pData_
unsigned char * _pData_
Pointer to the managed memory itself.
Definition
fixedAllocator.h:122
gum::FixedAllocator::_Chunk_::_release_
void _release_()
Releases the allocated memory.
Definition
fixedAllocator_inl.h:74
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0