Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

storage_ptr

A smart pointer to a memory_resource.

Synopsis

Defined in header <boost/json/storage_ptr.hpp>

class storage_ptr
Member Functions

Name

Description

get

Return a pointer to the memory resource.

is_deallocate_trivial

Return true if calling deallocate on the memory resource has no effect.

is_not_shared_and_deallocate_is_trivial

Return true if ownership of the memory resource is not shared and deallocate is trivial.

is_shared

Return true if ownership of the memory resource is shared.

operator=

Move assignment.

Copy assignment.

operator->

Return a pointer to the memory resource.

operator *

Return a reference to the memory resource.

storage_ptr [constructor]

Constructor.

Move constructor.

Copy constructor.

~storage_ptr [destructor]

Destructor.

Friends

Name

Description

make_shared_resource

Return shared ownership of a new, dynamically allocated memory resource.

Description

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:

Examples

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 >();
}
Thread Safety

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.

See Also

make_shared_resource, memory_resource, polymorphic_allocator

Convenience header <boost/json.hpp>


PrevUpHomeNext