Struct Allocator
Synopsis
#include <src/c4/yml/common.hpp>
struct RYML_EXPORT Allocator
Description
an allocator is a lightweight non-owning handle to a memory resource
Summary
Allocator overload | ||
allocate | ||
free |
Source
Lines 236-256 in src/c4/yml/common.hpp.
struct RYML_EXPORT Allocator
{
MemoryResource *r;
Allocator() : r(get_memory_resource()) {}
Allocator(MemoryResource *m) : r(m) {}
inline void *allocate(size_t num_bytes, void *hint)
{
void *mem = r->allocate(num_bytes, hint);
if(mem == nullptr)
error("out of memory");
return mem;
}
inline void free(void *mem, size_t num_bytes)
{
RYML_ASSERT(r != nullptr);
r->free(mem, num_bytes);
}
};