16#ifndef SIMICS_MALLOC_ALLOCATOR_H
17#define SIMICS_MALLOC_ALLOCATOR_H
19#include <simics/util/alloc.h>
31 return MM_MALLOC(num, T);
39template <
class T,
template <
class>
class Allocator = MmAllocator>
42 virtual T *
allocate(
const size_t num_elements)
const {
43 if (num_elements == 0) {
47 throw std::bad_alloc();
50 void *addr = Allocator<T>::allocate(num_elements);
52 throw std::bad_alloc();
54 return static_cast<T*
>(addr);
58 std::allocator_traits<std::allocator<void> >
64 Allocator<T>::deallocate(addr);
67 void construct(T *
const uninitialized,
const T &val)
const {
68 void *
const initialized =
static_cast<void*
>(uninitialized);
69 new(initialized) T(val);
77 return static_cast<size_t>(-1) /
sizeof(T);
93 return !(*
this == other);
100 template <
typename U>
Definition: malloc_allocator.h:40
T * allocate(const size_t num_elements, std::allocator_traits< std::allocator< void > > ::const_pointer hint) const
Definition: malloc_allocator.h:57
const T & const_reference
Definition: malloc_allocator.h:112
T value_type
Definition: malloc_allocator.h:114
bool operator==(const MallocAllocator &other) const
Definition: malloc_allocator.h:89
void destroy(T *const p) const
Definition: malloc_allocator.h:71
const T * address(const T &x) const
Definition: malloc_allocator.h:83
size_t size_type
Definition: malloc_allocator.h:115
ptrdiff_t difference_type
Definition: malloc_allocator.h:116
void deallocate(T *const addr, const size_t n) const
Definition: malloc_allocator.h:63
~MallocAllocator()
Definition: malloc_allocator.h:98
T & reference
Definition: malloc_allocator.h:111
MallocAllocator & operator=(const MallocAllocator &other) const
Definition: malloc_allocator.h:103
MallocAllocator(const MallocAllocator< U, Allocator > &)
Definition: malloc_allocator.h:101
MallocAllocator()
Definition: malloc_allocator.h:96
const T * const_pointer
Definition: malloc_allocator.h:109
T * address(T &x) const
Definition: malloc_allocator.h:80
T * pointer
Definition: malloc_allocator.h:108
MallocAllocator(const MallocAllocator &)
Definition: malloc_allocator.h:97
virtual T * allocate(const size_t num_elements) const
Definition: malloc_allocator.h:42
void construct(T *const uninitialized, const T &val) const
Definition: malloc_allocator.h:67
bool operator!=(const MallocAllocator &other) const
Definition: malloc_allocator.h:92
size_t max_size() const
Definition: malloc_allocator.h:76
Definition: malloc_allocator.h:28
static void * allocate(std::size_t num)
Definition: malloc_allocator.h:30
static void deallocate(T *const addr)
Definition: malloc_allocator.h:34
Definition: after-bank.h:33
Definition: malloc_allocator.h:118
MallocAllocator< U, Allocator > other
Definition: malloc_allocator.h:119