1 #ifndef ZSERIO_PMR_I_MEMORY_RESOURCE_H_INC
2 #define ZSERIO_PMR_I_MEMORY_RESOURCE_H_INC
5 #ifdef ZSERIO_MEMORY_RESOURCE_TRACING
50 void*
allocate(
size_t bytes,
size_t alignment =
alignof(max_align_t))
52 #ifdef ZSERIO_MEMORY_RESOURCE_TRACING
53 void*
const ptr = doAllocate(bytes, alignment);
54 std::cout <<
"MemoryResource::allocate bytes=" << bytes <<
" alignment=" << alignment <<
" -> "
55 << std::hex << ptr << std::dec << std::endl;
58 return doAllocate(bytes, alignment);
71 void deallocate(
void* storage,
size_t bytes,
size_t alignment =
alignof(max_align_t))
73 #ifdef ZSERIO_MEMORY_RESOURCE_TRACING
74 std::cout <<
"MemoryResource::deallocate p=" << std::hex << storage << std::dec <<
" bytes=" << bytes
75 <<
" alignment=" << alignment << std::endl;
77 doDeallocate(storage, bytes, alignment);
92 #ifdef ZSERIO_MEMORY_RESOURCE_TRACING
93 std::cout <<
"MemoryResource::isEqual other=" << std::hex << &other << std::dec << std::endl;
95 return doIsEqual(other);
107 virtual void* doAllocate(
size_t bytes,
size_t alignment) = 0;
118 virtual void doDeallocate(
void* storage,
size_t bytes,
size_t alignment) = 0;
130 virtual bool doIsEqual(
const MemoryResource& other)
const noexcept = 0;
143 return &lhs == &rhs || lhs.
isEqual(rhs);
156 return !(lhs == rhs);
MemoryResource(const MemoryResource &other)=delete
MemoryResource(MemoryResource &&other)=delete
void * allocate(size_t bytes, size_t alignment=alignof(max_align_t))
bool isEqual(const MemoryResource &other) const noexcept
MemoryResource & operator=(const MemoryResource &other)=delete
virtual ~MemoryResource()=default
MemoryResource & operator=(MemoryResource &&other)=delete
void deallocate(void *storage, size_t bytes, size_t alignment=alignof(max_align_t))
bool operator==(const MemoryResource &lhs, const MemoryResource &rhs)
MemoryResource * setDefaultResource(MemoryResource *resource) noexcept
MemoryResource * getDefaultResource() noexcept
bool operator!=(const MemoryResource &lhs, const MemoryResource &rhs)