Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

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 memory_resource
Member Functions

Name

Description

operator=

Copy assignment (deleted)

release

Release all allocated memory.

static_resource

Copy constructor (deleted)

~static_resource

Destructor.

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 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

https://en.wikipedia.org/wiki/Region-based_memory_management

Convenience header <boost/json.hpp>


PrevUpHomeNext