aGrUM  0.14.2
smallObjectAllocator.h
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
4  * {prenom.nom}_at_lip6.fr *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20  ***************************************************************************/
28 #ifndef GUM_SMALL_OBJECT_ALLOCATOR_H
29 #define GUM_SMALL_OBJECT_ALLOCATOR_H
30 
31 // ============================================================================
32 #include <agrum/agrum.h>
33 // ============================================================================
34 #include <agrum/core/hashTable.h>
36 // ============================================================================
37 
38 
39 namespace gum {
54  public:
60  static const size_t GUM_DEFAULT_CHUNK_SIZE;
61 
67  static const size_t GUM_DEFAULT_MAX_OBJECT_SIZE;
68 
69 
70  // ############################################################################
72  // ############################################################################
74  private:
75  // ============================================================================
80  // ============================================================================
82 
83  // ============================================================================
85  // ============================================================================
87 
88  // ============================================================================
90  // ============================================================================
92  return instance();
93  }
94 
95  public:
96  // ============================================================================
98  // ============================================================================
99  virtual ~SmallObjectAllocator();
100 
102 
103  static SmallObjectAllocator& instance();
104 
105  // ############################################################################
107  // ############################################################################
109  // ============================================================================
111  // ============================================================================
112  void* allocate(const size_t& objectSize);
113 
114  // ============================================================================
119  // ============================================================================
120  void deallocate(void* pDeallocatedObject, const size_t& objectSize);
121 
123 
124  // ============================================================================
126  // ============================================================================
127  void displayStats() {
128  GUM_TRACE("Nb Small Allocation : " << nbAllocation
129  << " - Nb Small Deallocation : "
130  << nbDeallocation);
131  }
132 
133  Idx nbAlloc() { return nbAllocation; }
135 
136  private:
137  // ============================================================================
139  // ============================================================================
141  __Pool __pool;
142 
143  // ============================================================================
145  // ============================================================================
146  std::size_t __chunkSize;
147 
148  // ============================================================================
150  // ============================================================================
151  std::size_t __maxObjectSize;
152 
155  };
156 } // namespace gum
157 
158 // Macro used to shorten code in classes using SmallObjectAllocator
159 #define SOA_ALLOCATE(x) SmallObjectAllocator::instance().allocate(x)
160 #define SOA_DEALLOCATE(x, y) SmallObjectAllocator::instance().deallocate(x, y)
161 
162 #ifndef GUM_NO_INLINE
164 #endif
165 
166 #endif // GUM_SMALL_OBJECT_ALLOCATOR_H
SmallObjectAllocator & operator=(const SmallObjectAllocator &)
Operator = (does nothing since we use a Singleton)
Inlines of gum::SmallObjectAllocator.
static const size_t GUM_DEFAULT_MAX_OBJECT_SIZE
static const size_t GUM_DEFAULT_CHUNK_SIZE
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
HashTable< Size, FixedAllocator *> __Pool
The pool containing FixedAllocator.
virtual ~SmallObjectAllocator()
Destructor.
SmallObjectAllocator(const SmallObjectAllocator &)
Copy Constructor (does nothing since we use a Singleton)
<agrum/core/smallObjectAllocator.h>
void displayStats()
Displays the number of allocation and deallocation made so far.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
std::size_t __maxObjectSize
The maximal size of an object befor new is called.
Size Idx
Type for indexes.
Definition: types.h:50
void * allocate(const size_t &objectSize)
Allocates a block.
static SmallObjectAllocator & instance()
std::size_t __chunkSize
The memory that a chunk allocates.
Headers of gum::FixedAllocator.
Class hash tables iterators.