|
CookMem 1.6.0
A C++ memory context / allocator
|
#include <memresource.h>


Public Member Functions | |
| MemResource (Context &context) noexcept | |
| Context & | getContext () const noexcept |
Protected Member Functions | |
| void * | do_allocate (std::size_t bytes, std::size_t alignment) override |
| void | do_deallocate (void *ptr, std::size_t bytes, std::size_t alignment) override |
| bool | do_is_equal (const std::pmr::memory_resource &other) const noexcept override |
A std::pmr::memory_resource that allocates from a memory context, so that the std::pmr containers can use it. It needs C++17, and is available when COOKMEM_HAS_PMR is 1.
Alignments larger than the allocation alignment use allocateAligned (). When the context cannot allocate the memory, std::bad_alloc is thrown, as std::pmr::memory_resource requires.
| Context | a memory context, such as cookmem::MemContext or cookmem::SimpleMemContext, with void as the value type. |
|
inlineexplicitnoexcept |
Constructor.
| context | the memory context to allocate from. The caller owns it, and it must outlive this resource and the memory allocated from it. |
|
inlineoverrideprotected |
Allocate memory from the context.
| bytes | the size of the memory. |
| alignment | the alignment of the memory, a power of two. |
| std::bad_alloc | if the memory cannot be allocated. |
|
inlineoverrideprotected |
Free memory allocated by do_allocate ().
| ptr | the memory to free. |
| bytes | the size of the memory, which is only passed to the logger. |
| alignment | the alignment of the memory, which is not needed. |
|
inlineoverrideprotectednoexcept |
Check whether memory allocated by this resource can be freed by another resource. That is the case when the other resource is a MemResource of the same type for the same context.
| other | the other resource. |
|
inlinenoexcept |
Get the memory context.