...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
A resource using a caller-owned buffer, with a trivial deallocate.
Defined in header <boost/json/static_resource.hpp>
class static_resource
: public boost::container::pmr::memory_resource
;
Name |
Description |
---|---|
Copy assignment (deleted) |
|
Release all allocated memory. |
|
static_resource [constructor] |
Constructor. |
This memory resource is a special-purpose resource that releases allocated
memory only when the resource is destroyed (or when release
is called). It has a trivial
deallocate function; that is, the metafunction is_deallocate_trivial
returns true
.
The resource is constructed from a caller-owned buffer from which subsequent
calls to allocate are apportioned. When a memory request cannot be satisfied
from the free bytes remaining in the buffer, the allocation request fails
with the exception std::bad_alloc
.
This parses a JSON text into a value which uses a local stack buffer, then prints the result.
unsigned char buf[ 4000 ]; static_resource mr( buf ); // Parse the string, using our memory resource value const jv = parse( "[1,2,3]", &mr ); // Print the JSON std::cout << jv;
Members of the same instance may not be called concurrently.
https://en.wikipedia.org/wiki/Region-based_memory_management
Convenience header <boost/json.hpp>