1 #ifndef ZSERIO_PMR_I_MEMORY_RESOURCE_H_INC
2 #define ZSERIO_PMR_I_MEMORY_RESOURCE_H_INC
4 #ifdef ZSERIO_MEMORY_RESOURCE_TRACING
51 void*
allocate(
size_t bytes,
size_t alignment =
alignof(max_align_t))
53 #ifdef ZSERIO_MEMORY_RESOURCE_TRACING
54 void*
const ptr = doAllocate(bytes, alignment);
55 std::cout <<
"MemoryResource::allocate bytes=" << bytes <<
" alignment=" << alignment <<
" -> "
56 << std::hex << ptr << std::dec << std::endl;
59 return doAllocate(bytes, alignment);
72 void deallocate(
void* storage,
size_t bytes,
size_t alignment =
alignof(max_align_t))
74 #ifdef ZSERIO_MEMORY_RESOURCE_TRACING
75 std::cout <<
"MemoryResource::deallocate p=" << std::hex << storage << std::dec <<
" bytes=" << bytes
76 <<
" alignment=" << alignment << std::endl;
78 doDeallocate(storage, bytes, alignment);
93 #ifdef ZSERIO_MEMORY_RESOURCE_TRACING
94 std::cout <<
"MemoryResource::isEqual other=" << std::hex << &other << std::dec << std::endl;
96 return doIsEqual(other);
108 virtual void* doAllocate(
size_t bytes,
size_t alignment) = 0;
119 virtual void doDeallocate(
void* storage,
size_t bytes,
size_t alignment) = 0;
131 virtual bool doIsEqual(
const MemoryResource& other)
const noexcept = 0;
144 return &lhs == &rhs || lhs.
isEqual(rhs);
157 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)