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

Persistent_ptr allocation functions for arrays. More...

#include <libpmemobj++/detail/array_traits.hpp>
#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 <cassert>
#include <limits>

Go to the source code of this file.

Functions

template<typename T >
detail::pp_if_array< T >::type pmem::obj::make_persistent (std::size_t N)
 Transactionally allocate and construct an array of objects of type T. More...
 
template<typename T >
detail::pp_if_size_array< T >::type pmem::obj::make_persistent ()
 Transactionally allocate and construct an array of objects of type T. More...
 
template<typename T >
void pmem::obj::delete_persistent (typename detail::pp_if_array< T >::type ptr, std::size_t N)
 Transactionally free an array of objects of type T held in a persistent_ptr. More...
 
template<typename T >
void pmem::obj::delete_persistent (typename detail::pp_if_size_array< T >::type ptr)
 Transactionally free an array of objects of type T held in a persistent_ptr. More...
 

Detailed Description

Persistent_ptr allocation functions for arrays.

The typical usage examples would be:

#include <fcntl.h>
using namespace pmem::obj;
void
make_persistent_array_example()
{
struct compound_type {
compound_type() : some_variable(0), some_other_variable(0)
{
}
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, [&] {
// allocate an array of 20 objects - compound_type must be
// default constructible
proot->comp = make_persistent<compound_type[]>(20);
// another allocation method
auto arr1 = make_persistent<compound_type[3]>();
// transactionally delete arrays , ~compound_type() is called
delete_persistent<compound_type[]>(proot->comp, 20);
delete_persistent<compound_type[3]>(arr1);
});
// throws an transaction_scope_error exception
auto arr1 = make_persistent<compound_type[3]>();
delete_persistent<compound_type[3]>(arr1);
}

Function Documentation

◆ delete_persistent() [1/2]

template<typename T >
void pmem::obj::delete_persistent ( typename detail::pp_if_array< T >::type  ptr,
std::size_t  N 
)

Transactionally free an array of objects of type T held in a persistent_ptr.

This function can be used to transactionally free an array of objects. Calls the objects' destructors before freeing memory. This overload only participates in overload resolution if T is an array.

Parameters
[in,out]ptrpersistent pointer to an array of objects.
[in]Nthe size of the array.
Exceptions
transaction_scope_errorif called outside of an active transaction
transaction_free_erroron transactional free failure.

◆ delete_persistent() [2/2]

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

Transactionally free an array of objects of type T held in a persistent_ptr.

This function can be used to transactionally free an array of objects. Calls the objects' destructors before freeing memory. This overload only participates in overload resolution if T is an array.

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

◆ make_persistent() [1/2]

template<typename T >
detail::pp_if_array<T>::type pmem::obj::make_persistent ( std::size_t  N)

Transactionally allocate and construct an array of objects of type T.

This function can be used to transactionally allocate an array. This overload only participates in overload resolution if T is an array.

Parameters
[in]Nthe number of array elements.
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

◆ make_persistent() [2/2]

template<typename T >
detail::pp_if_size_array<T>::type pmem::obj::make_persistent ( )

Transactionally allocate and construct an array of objects of type T.

This function can be used to transactionally allocate an array. This overload only participates in overload resolution if T is an array.

Returns
persistent_ptr<T[N]> on success
Exceptions
transaction_scope_errorif called outside of an active transaction
transaction_alloc_erroron transactional allocation failure.
rethrowexception from T constructor