PMDK C++ bindings  1.5.2
This is the C++ bindings documentation for PMDK's libpmemobj.
Functions
make_persistent.hpp File Reference

Persistent_ptr transactional allocation functions for objects. More...

#include <libpmemobj++/detail/check_persistent_ptr_array.hpp>
#include <libpmemobj++/detail/common.hpp>
#include <libpmemobj++/detail/life.hpp>
#include <libpmemobj++/detail/pexceptions.hpp>
#include <libpmemobj/tx_base.h>
#include <new>
#include <utility>

Go to the source code of this file.

Functions

template<typename T , typename... Args>
detail::pp_if_not_array< T >::type pmem::obj::make_persistent (Args &&... args)
 Transactionally allocate and construct an object of type T. More...
 
template<typename T >
void pmem::obj::delete_persistent (typename detail::pp_if_not_array< T >::type ptr)
 Transactionally free an object of type T held in a persistent_ptr. More...
 

Detailed Description

Persistent_ptr transactional allocation functions for objects.

The typical usage examples would be:

#include <fcntl.h>
using namespace pmem::obj;
void
make_persistent_example()
{
struct compound_type {
compound_type(int val, double dval)
: some_variable(val), some_other_variable(dval)
{
}
void
set_some_variable(int val)
{
some_variable = val;
}
p<int> some_variable;
p<double> some_other_variable;
};
// pool root structure
struct root {
};
// create a pmemobj pool
auto pop = pool<root>::create("poolfile", "layout", PMEMOBJ_MIN_POOL);
auto proot = pop.root();
// typical usage schemes
transaction::run(pop, [&] {
// allocation with constructor argument passing
proot->comp = make_persistent<compound_type>(1, 2.0);
// transactionally delete the object, ~compound_type() is called
delete_persistent<compound_type>(proot->comp);
});
// throws an transaction_scope_error exception
auto arr1 = make_persistent<compound_type>(2, 15.0);
delete_persistent<compound_type>(arr1);
}

Function Documentation

◆ delete_persistent()

template<typename T >
void pmem::obj::delete_persistent ( typename detail::pp_if_not_array< T >::type  ptr)

Transactionally free an object of type T held in a persistent_ptr.

This function can be used to transactionally free an object. Calls the object's destructor before freeing memory. Cannot be used for array types.

Parameters
[in,out]ptrpersistent pointer to an object that is not an array.
Exceptions
transaction_scope_errorif called outside of an active transaction
transaction_free_erroron transactional free failure.

◆ make_persistent()

template<typename T , typename... Args>
detail::pp_if_not_array<T>::type pmem::obj::make_persistent ( Args &&...  args)

Transactionally allocate and construct an object of type T.

This function can be used to transactionally allocate an object. Cannot be used for array types.

Parameters
[in,out]argsa list of parameters passed to the constructor.
Returns
persistent_ptr<T> on success
Exceptions
transaction_scope_errorif called outside of an active transaction
transaction_alloc_erroron transactional allocation failure.
rethrowexception from T constructor
pmem::obj::pool::create
static pool< T > create(const std::string &path, const std::string &layout, std::size_t size=PMEMOBJ_MIN_POOL, mode_t mode=DEFAULT_MODE)
Creates a new transactional object store pool.
Definition: pool.hpp:532
pmem::obj::p
Resides on pmem class.
Definition: p.hpp:64
pool.hpp
C++ pmemobj pool.
make_persistent.hpp
Persistent_ptr transactional allocation functions for objects.
pmem::obj::transaction::run
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:401
transaction.hpp
C++ pmemobj transactions.
pmem::obj::persistent_ptr
Persistent pointer class.
Definition: persistent_ptr.hpp:132
p.hpp
Resides on pmem property template.
persistent_ptr.hpp
Persistent smart pointer.