1 #ifndef _RHEOLEF_HEAP_ALLOCATOR_H
2 #define _RHEOLEF_HEAP_ALLOCATOR_H
26 #include "rheolef/compiler.h"
27 #include "rheolef/pretty_name.h"
62 #define _RHEOLEF_DO_NOT_USE_HEAP_ALLOCATOR
63 #ifdef _RHEOLEF_DO_NOT_USE_HEAP_ALLOCATOR
65 #else // _RHEOLEF_DO_NOT_USE_HEAP_ALLOCATOR
107 template <
typename U>
132 new( reinterpret_cast<void*>(
p) )
T(
c);
166 template <
typename T1>
169 return lhs.get_handler() == rhs.get_handler();
171 template <
typename T1>
174 return lhs.get_handler() != rhs.get_handler();
187 unsigned char* raw_allocate (
size_type size);
189 std::list<std::vector<unsigned char> >
heap;
199 heap_block_size (heap_block_size_init),
200 heap_block_last_free (0),
210 if (heap_block_last_free + size > heap_block_size) {
211 heap_block_size = std::max (size, 2*heap_block_size);
212 heap.push_front (std::vector<unsigned char>(heap_block_size));
213 heap_block_last_free = 0;
215 std::vector<unsigned char>& block = *(heap.begin());
216 unsigned char*
p = &(block [heap_block_last_free]);
217 heap_block_last_free += size;
224 heap.erase (heap.begin(), heap.end());
227 #endif // _RHEOLEF_DO_NOT_USE_HEAP_ALLOCATOR
230 #endif // _RHEOLEF_HEAP_ALLOCATOR_H