rapidyaml  0.12.1
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 5707 of file quickstart.cpp.

Constructor & Destructor Documentation

◆ ~PerTreeMemoryExample()

PerTreeMemoryExample::~PerTreeMemoryExample ( )
inline

Definition at line 5749 of file quickstart.cpp.

Member Function Documentation

◆ callbacks()

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

Definition at line 5713 of file quickstart.cpp.

5719 {
5720  std::vector<char> memory_pool = std::vector<char>(10u * 1024u); // 10KB
5721  size_t num_allocs = 0, alloc_size = 0, corr_size = 0;
5722  size_t num_deallocs = 0, dealloc_size = 0;
5723 
5724  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 5726 of file quickstart.cpp.

5733  {
5734  uintptr_t prev = uptr - (uptr % align);
5735  uintptr_t next = prev + align;
5736  uintptr_t corr = next - uptr;
5737  ptr = (void*)(((char*)ptr) + corr);

References GlobalAllocatorExample::corr_size.

◆ free()

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

Definition at line 5739 of file quickstart.cpp.

5747  {

◆ check_and_reset()

void PerTreeMemoryExample::check_and_reset ( )
inline

Definition at line 5753 of file quickstart.cpp.

5757  {
5758  ryml::Callbacks cb = {};
5759  return cb.set_user_data(this)
5762  }
5763  static void* s_allocate(size_t len, void* /*hint*/, void *this_)
5764  {
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:538
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 5709 of file quickstart.cpp.

◆ num_allocs

size_t PerTreeMemoryExample::num_allocs = 0

Definition at line 5710 of file quickstart.cpp.

◆ alloc_size

size_t PerTreeMemoryExample::alloc_size = 0

Definition at line 5710 of file quickstart.cpp.

◆ num_deallocs

size_t PerTreeMemoryExample::num_deallocs = 0

Definition at line 5711 of file quickstart.cpp.

◆ dealloc_size

size_t PerTreeMemoryExample::dealloc_size = 0

Definition at line 5711 of file quickstart.cpp.


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