aGrUM  0.16.0
smallObjectAllocator.h
Go to the documentation of this file.
1 
30 #ifndef GUM_SMALL_OBJECT_ALLOCATOR_H
31 #define GUM_SMALL_OBJECT_ALLOCATOR_H
32 
33 // ============================================================================
34 #include <agrum/agrum.h>
35 // ============================================================================
36 #include <agrum/core/hashTable.h>
38 // ============================================================================
39 
40 
41 namespace gum {
56  public:
62  static const size_t GUM_DEFAULT_CHUNK_SIZE;
63 
69  static const size_t GUM_DEFAULT_MAX_OBJECT_SIZE;
70 
71 
72  // ############################################################################
74  // ############################################################################
76  private:
77  // ============================================================================
82  // ============================================================================
84 
85  // ============================================================================
87  // ============================================================================
89 
90  // ============================================================================
92  // ============================================================================
94  return instance();
95  }
96 
97  public:
98  // ============================================================================
100  // ============================================================================
101  virtual ~SmallObjectAllocator();
102 
104 
105  static SmallObjectAllocator& instance();
106 
107  // ############################################################################
109  // ############################################################################
111  // ============================================================================
113  // ============================================================================
114  void* allocate(const size_t& objectSize);
115 
116  // ============================================================================
121  // ============================================================================
122  void deallocate(void* pDeallocatedObject, const size_t& objectSize);
123 
125 
126  // ============================================================================
128  // ============================================================================
129  void displayStats() {
130  GUM_TRACE("Nb Small Allocation : " << nbAllocation
131  << " - Nb Small Deallocation : "
132  << nbDeallocation);
133  }
134 
135  Idx nbAlloc() { return nbAllocation; }
137 
138  private:
139  // ============================================================================
141  // ============================================================================
143  __Pool __pool;
144 
145  // ============================================================================
147  // ============================================================================
148  std::size_t __chunkSize;
149 
150  // ============================================================================
152  // ============================================================================
153  std::size_t __maxObjectSize;
154 
157  };
158 } // namespace gum
159 
160 // Macro used to shorten code in classes using SmallObjectAllocator
161 #define SOA_ALLOCATE(x) SmallObjectAllocator::instance().allocate(x)
162 #define SOA_DEALLOCATE(x, y) SmallObjectAllocator::instance().deallocate(x, y)
163 
164 #ifndef GUM_NO_INLINE
166 #endif
167 
168 #endif // GUM_SMALL_OBJECT_ALLOCATOR_H
SmallObjectAllocator & operator=(const SmallObjectAllocator &)
Operator = (does nothing since we use a Singleton)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
static const size_t GUM_DEFAULT_MAX_OBJECT_SIZE
static const size_t GUM_DEFAULT_CHUNK_SIZE
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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:53
void * allocate(const size_t &objectSize)
Allocates a block.
static SmallObjectAllocator & instance()
std::size_t __chunkSize
The memory that a chunk allocates.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.