static_resource
A resource using a caller-owned buffer, with a trivial deallocate.
Synopsis
Defined in header <boost/json/static_resource.hpp>.
class static_resource
: public boost::container::pmr::memory_resource;
Member Functions
Name | Description |
---|---|
Copy assignment (deleted) |
|
Release all allocated memory. |
|
|
Constructor. |
Description
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
.
Example
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;
Thread Safety
Members of the same instance may not be called concurrently.
See Also
Convenience header <boost/json.hpp>.