CETL 0.0.0
 
Loading...
Searching...
No Matches
o1heap_memory_resource_delegate.hpp File Reference
#include "cetl/cetl.hpp"
#include <cstddef>
#include <new>
#include "o1heap.h"
Include dependency graph for o1heap_memory_resource_delegate.hpp:

Classes

struct  cetl::pmr::O1HeapAlignedStorage< StorageSizeBytes >
 
struct  cetl::pmr::O1HeapAlignedStorage< StorageSizeBytes >::type
 
class  cetl::pmr::UnsynchronizedO1HeapMemoryResourceDelegate
 

Namespaces

namespace  cetl
 
namespace  cetl::pmr
 

Detailed Description

Defines cetl::pmr::O1HeapMemoryResource which is a std::pmr::memory_resource implemented in terms of Pavel Kirienko's o1heap.

If including this file you will need to either first include cetl/pf17/cetlpf.hpp or provide the memory_resource definition you want this class to use. You'll also need to provide an include path to o1heap.h and compile in o1heap.c when using this type.

// We'll use the aligned-storage helper class to defined properly aligned storage for the 01-heap areana. As this
// is a large chunk we'll make it static to keep it off the stack.
static cetl::pmr::O1HeapAlignedStorage<0x100000> large_buffer{};
// Now we can use our test subject to allocate and deallocate memory.
cetl::pmr::UnsynchronizedO1HeapMemoryResourceDelegate test_subject{large_buffer};
// Note that, until https://github.com/pavel-kirienko/o1heap/issues/13 is fixed the alignment doesn't have
// any effect on allocation requests.
void* mem = test_subject.allocate(8);
ASSERT_NE(nullptr, mem);
test_subject.deallocate(mem, 8);