1#ifndef _RHEOLEF_HEAP_ALLOCATOR_H
2#define _RHEOLEF_HEAP_ALLOCATOR_H
26#include "rheolef/compiler.h"
27#include "rheolef/pretty_name.h"
63#ifndef _RHEOLEF_USE_HEAP_ALLOCATOR
111 template <
typename U>
136 new(
reinterpret_cast<void*
>(
p) )
T(c);
170template <
typename T1>
175template <
typename T1>
178 return lhs.get_handler() != rhs.get_handler();
191 unsigned char* raw_allocate (
size_type size);
193 std::list<std::vector<unsigned char> >
heap;
203 heap_block_size (heap_block_size_init),
204 heap_block_last_free (0),
214 if (heap_block_last_free + size > heap_block_size) {
215 heap_block_size = std::max (size, 2*heap_block_size);
216 heap.push_front (std::vector<unsigned char>(heap_block_size));
217 heap_block_last_free = 0;
219 std::vector<unsigned char>& block = *(heap.begin());
220 unsigned char*
p = &(block [heap_block_last_free]);
221 heap_block_last_free += size;
228 heap.erase (heap.begin(), heap.end());
239struct allocator_traits<
rheolef::heap_allocator<T>> {
246 using void_pointer =
typename std::pointer_traits<pointer>::rebind<
void>;
249 using size_type =
typename std::make_unsigned<difference_type>::type;
heap_allocator(const heap_allocator &ha)
const handler_type * get_handler() const
heap_allocator & operator=(const heap_allocator &ha)
pointer allocate(size_type n, const void *=NULL)
pointer address(reference r) const
void construct(pointer p, const_reference c)
void construct(pointer p)
size_type max_size() const
heap_allocator(const heap_allocator< U > &ha)
std::ptrdiff_t difference_type
void deallocate(pointer p, size_type n)
const_pointer address(const_reference c) const
const T & const_reference
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
This file is part of Rheolef.
bool operator!=(const heap_allocator< T1 > &lhs, const heap_allocator< T1 > &rhs)
bool operator==(const heap_allocator< T1 > &lhs, const heap_allocator< T1 > &rhs)
size_type reference_count
size_type heap_block_last_free
unsigned char * raw_allocate(size_type size)
size_type heap_block_size
std::list< std::vector< unsigned char > > heap
heap_allocator< U > other
typename std::pointer_traits< pointer >::difference_type difference_type
std::false_type propagate_on_container_move_assignment
typename std::pointer_traits< pointer >::rebind< const void > const_void_pointer
typename std::pointer_traits< pointer >::rebind< const value_type > const_pointer
std::false_type propagate_on_container_swap
static void deallocate(allocator_type &a, pointer p, size_type n)
typename std::pointer_traits< pointer >::rebind< void > void_pointer
static void construct(allocator_type &a, pointer p, const T &c)
static pointer allocate(allocator_type &a, size_type n)
rheolef::heap_allocator< U > rebind_alloc
typename std::make_unsigned< difference_type >::type size_type
std::false_type propagate_on_container_copy_assignment
static size_type max_size(const allocator_type &a)
rheolef::heap_allocator< T > allocator_type
static void construct(allocator_type &a, pointer p)
typename std::is_empty< rheolef::heap_allocator< T > >::type is_always_equal
static void destroy(allocator_type &a, U *p)