rapidyaml  0.11.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 5695 of file quickstart.cpp.

Constructor & Destructor Documentation

◆ ~PerTreeMemoryExample()

PerTreeMemoryExample::~PerTreeMemoryExample ( )
inline

Definition at line 5737 of file quickstart.cpp.

Member Function Documentation

◆ callbacks()

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

Definition at line 5701 of file quickstart.cpp.

5707 {
5708  std::vector<char> memory_pool = std::vector<char>(10u * 1024u); // 10KB
5709  size_t num_allocs = 0, alloc_size = 0, corr_size = 0;
5710  size_t num_deallocs = 0, dealloc_size = 0;
5711 
5712  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 5714 of file quickstart.cpp.

5721  {
5722  uintptr_t prev = uptr - (uptr % align);
5723  uintptr_t next = prev + align;
5724  uintptr_t corr = next - uptr;
5725  ptr = (void*)(((char*)ptr) + corr);

References GlobalAllocatorExample::corr_size.

◆ free()

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

Definition at line 5727 of file quickstart.cpp.

5735  {

◆ check_and_reset()

void PerTreeMemoryExample::check_and_reset ( )
inline

Definition at line 5741 of file quickstart.cpp.

5745  {
5746  ryml::Callbacks cb = {};
5747  return cb.set_user_data(this)
5750  }
5751  static void* s_allocate(size_t len, void* /*hint*/, void *this_)
5752  {
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 5697 of file quickstart.cpp.

◆ num_allocs

size_t PerTreeMemoryExample::num_allocs = 0

Definition at line 5698 of file quickstart.cpp.

◆ alloc_size

size_t PerTreeMemoryExample::alloc_size = 0

Definition at line 5698 of file quickstart.cpp.

◆ num_deallocs

size_t PerTreeMemoryExample::num_deallocs = 0

Definition at line 5699 of file quickstart.cpp.

◆ dealloc_size

size_t PerTreeMemoryExample::dealloc_size = 0

Definition at line 5699 of file quickstart.cpp.


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