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

Persistent_ptr allocation functions for arrays. More...

#include <libpmemobj++/allocation_flag.hpp>
#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/variadic.hpp>
#include <libpmemobj++/pexceptions.hpp>
#include <libpmemobj/tx_base.h>
#include <cassert>
#include <limits>

Go to the source code of this file.

Namespaces

 pmem
 Persistent memory namespace.
 
 pmem::obj
 Main libpmemobj namespace.
 

Functions

template<typename T >
detail::pp_if_array< T >::type pmem::obj::make_persistent (std::size_t N, allocation_flag flag=allocation_flag::none())
 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 (allocation_flag flag=allocation_flag::none())
 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);
// set pointer to null so that after restart it's known whether
// compound_type is still allocated or not
proot->comp = nullptr;
});
// throws an transaction_scope_error exception
auto arr1 = make_persistent<compound_type[3]>();
delete_persistent<compound_type[3]>(arr1);
}
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:701
pmem::obj::p
Resides on pmem class.
Definition: p.hpp:64
make_persistent_array.hpp
Persistent_ptr allocation functions for arrays.
pool.hpp
C++ pmemobj pool.
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:422
pmem::obj
Main libpmemobj namespace.
Definition: allocation_flag.hpp:47
transaction.hpp
C++ pmemobj transactions.
pmem::obj::persistent_ptr
Persistent pointer class.
Definition: persistent_ptr.hpp:212
p.hpp
Resides on pmem property template.
persistent_ptr.hpp
Persistent smart pointer.