...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
A smart pointer to a memory_resource
.
Defined in header <boost/json/storage_ptr.hpp>
class storage_ptr
Name |
Description |
---|---|
Return a pointer to the memory resource. |
|
Return |
|
Return |
|
Return |
|
Return a reference to the memory resource. |
|
Return a pointer to the memory resource. |
|
Move assignment. |
|
storage_ptr [constructor] |
Constructor. |
~storage_ptr [destructor] |
Destructor. |
Name |
Description |
---|---|
Return shared ownership of a new, dynamically allocated memory resource. |
This container is used to hold a pointer to a memory resource. The pointed-to resource is always valid; default-constructed pointers use the default memory resource, which calls into the standard global system heap. Depending on the means of construction, the ownership will be either:
memory_resource
or from a polymorphic_allocator
.
In this case the caller is responsible for ensuring that the lifetime
of the memory resource extends until there are no more calls to allocate
or deallocate.
make_shared_resource
. In this
case ownership is shared; the lifetime of the memory resource extends
until the last copy of the storage_ptr
is destroyed.
These statements create a memory resource on the stack and construct a pointer from it without taking ownership:
monotonic_resource mr; // Create our memory resource on the stack storage_ptr sp( &mr ); // Construct a non-owning pointer to the resource
This function creates a pointer to a memory resource using shared ownership and returns it. The lifetime of the memory resource extends until the last copy of the pointer is destroyed:
// Create a counted memory resource and return it storage_ptr make_storage() { return make_shared_resource< monotonic_resource >(); }
Instances of this type provide the default level of thread safety for all C++ objects. Specifically, it conforms to 16.4.6.10 Data race avoidance.
make_shared_resource
, memory_resource
, polymorphic_allocator
Convenience header <boost/json.hpp>