16#ifndef SIMICS_MALLOC_ALLOCATOR_H
17#define SIMICS_MALLOC_ALLOCATOR_H
19#include <simics/util/alloc.h>
32 return MM_MALLOC(num, T);
40template <
class T,
template <
class>
class Allocator = MmAllocator>
43 virtual T *
allocate(
const size_t num_elements)
const {
44 if (num_elements == 0) {
48 throw std::bad_alloc();
51 void *addr = Allocator<T>::allocate(num_elements);
53 throw std::bad_alloc();
55 return static_cast<T*
>(addr);
59 std::allocator_traits<std::allocator<void> >
65 Allocator<T>::deallocate(addr);
68 void construct(T *
const uninitialized,
const T &val)
const {
69 void *
const initialized =
static_cast<void*
>(uninitialized);
70 new(initialized) T(val);
78 return static_cast<size_t>(-1) /
sizeof(T);
94 return !(*
this == other);
101 template <
typename U>
#define NULL
Definition: _null.h:24
Definition: malloc_allocator.h:41
T * allocate(const size_t num_elements, std::allocator_traits< std::allocator< void > > ::const_pointer hint) const
Definition: malloc_allocator.h:58
const T & const_reference
Definition: malloc_allocator.h:113
T value_type
Definition: malloc_allocator.h:115
bool operator==(const MallocAllocator &other) const
Definition: malloc_allocator.h:90
void destroy(T *const p) const
Definition: malloc_allocator.h:72
const T * address(const T &x) const
Definition: malloc_allocator.h:84
size_t size_type
Definition: malloc_allocator.h:116
ptrdiff_t difference_type
Definition: malloc_allocator.h:117
void deallocate(T *const addr, const size_t n) const
Definition: malloc_allocator.h:64
~MallocAllocator()
Definition: malloc_allocator.h:99
T & reference
Definition: malloc_allocator.h:112
MallocAllocator & operator=(const MallocAllocator &other) const
Definition: malloc_allocator.h:104
MallocAllocator(const MallocAllocator< U, Allocator > &)
Definition: malloc_allocator.h:102
MallocAllocator()
Definition: malloc_allocator.h:97
const T * const_pointer
Definition: malloc_allocator.h:110
T * address(T &x) const
Definition: malloc_allocator.h:81
T * pointer
Definition: malloc_allocator.h:109
MallocAllocator(const MallocAllocator &)
Definition: malloc_allocator.h:98
virtual T * allocate(const size_t num_elements) const
Definition: malloc_allocator.h:43
void construct(T *const uninitialized, const T &val) const
Definition: malloc_allocator.h:68
bool operator!=(const MallocAllocator &other) const
Definition: malloc_allocator.h:93
size_t max_size() const
Definition: malloc_allocator.h:77
Definition: malloc_allocator.h:29
static void * allocate(std::size_t num)
Definition: malloc_allocator.h:31
static void deallocate(T *const addr)
Definition: malloc_allocator.h:35
Definition: attr-value.h:23
Definition: malloc_allocator.h:119
MallocAllocator< U, Allocator > other
Definition: malloc_allocator.h:120