rapidyaml  0.11.0
parse and emit YAML, and do it fast
PerTreeMemoryExample Struct Reference

an example for a per-tree memory allocator More...

Public Member Functions

ryml::Callbacks callbacks () const
 
void * allocate (size_t len)
 
void free (void *mem, size_t len)
 
 ~PerTreeMemoryExample ()
 
void check_and_reset ()
 

Public Attributes

std::vector< char > memory_pool = std::vector<char>(10u * 1024u)
 
size_t num_allocs = 0
 
size_t alloc_size = 0
 
size_t num_deallocs = 0
 
size_t dealloc_size = 0
 

Detailed Description

an example for a per-tree memory allocator

Definition at line 5678 of file quickstart.cpp.

Constructor & Destructor Documentation

◆ ~PerTreeMemoryExample()

PerTreeMemoryExample::~PerTreeMemoryExample ( )
inline

Definition at line 5720 of file quickstart.cpp.

Member Function Documentation

◆ callbacks()

ryml::Callbacks PerTreeMemoryExample::callbacks ( ) const
inline

Definition at line 5684 of file quickstart.cpp.

5690 {
5691  std::vector<char> memory_pool = std::vector<char>(10u * 1024u); // 10KB
5692  size_t num_allocs = 0, alloc_size = 0, corr_size = 0;
5693  size_t num_deallocs = 0, dealloc_size = 0;
5694 
5695  void *allocate(size_t len)
std::vector< char > memory_pool
void * allocate(size_t len)

References GlobalAllocatorExample::alloc_size, GlobalAllocatorExample::allocate(), GlobalAllocatorExample::corr_size, GlobalAllocatorExample::dealloc_size, GlobalAllocatorExample::memory_pool, GlobalAllocatorExample::num_allocs, and GlobalAllocatorExample::num_deallocs.

◆ allocate()

void* PerTreeMemoryExample::allocate ( size_t  len)
inline

Definition at line 5697 of file quickstart.cpp.

5704  {
5705  uintptr_t prev = uptr - (uptr % align);
5706  uintptr_t next = prev + align;
5707  uintptr_t corr = next - uptr;
5708  ptr = (void*)(((char*)ptr) + corr);

References GlobalAllocatorExample::corr_size.

◆ free()

void PerTreeMemoryExample::free ( void *  mem,
size_t  len 
)
inline

Definition at line 5710 of file quickstart.cpp.

5718  {

◆ check_and_reset()

void PerTreeMemoryExample::check_and_reset ( )
inline

Definition at line 5724 of file quickstart.cpp.

5728  {
5729  ryml::Callbacks cb = {};
5730  return cb.set_user_data(this)
5733  }
5734  static void* s_allocate(size_t len, void* /*hint*/, void *this_)
5735  {
static void s_free(void *mem, size_t len, void *this_)
static void * s_allocate(size_t len, void *, void *this_)
A c-style callbacks class to customize behavior on errors or allocation.
Definition: common.hpp:511
Callbacks & set_free(pfn_free free=nullptr)
Set or reset the free callback.
Definition: common.cpp:159
Callbacks & set_allocate(pfn_allocate allocate=nullptr)
Set or reset the allocate callback.
Definition: common.cpp:150
Callbacks & set_user_data(void *user_data)
Set the user data.
Definition: common.cpp:144

Member Data Documentation

◆ memory_pool

std::vector<char> PerTreeMemoryExample::memory_pool = std::vector<char>(10u * 1024u)

Definition at line 5680 of file quickstart.cpp.

◆ num_allocs

size_t PerTreeMemoryExample::num_allocs = 0

Definition at line 5681 of file quickstart.cpp.

◆ alloc_size

size_t PerTreeMemoryExample::alloc_size = 0

Definition at line 5681 of file quickstart.cpp.

◆ num_deallocs

size_t PerTreeMemoryExample::num_deallocs = 0

Definition at line 5682 of file quickstart.cpp.

◆ dealloc_size

size_t PerTreeMemoryExample::dealloc_size = 0

Definition at line 5682 of file quickstart.cpp.


The documentation for this struct was generated from the following file: