|
| persistent_ptr (persistent_ptr< void > const &rhs) noexcept |
| Explicit void specialization of the converting constructor.
|
|
| persistent_ptr (persistent_ptr< const void > const &rhs) noexcept |
| Explicit const void specialization of the converting constructor.
|
|
| persistent_ptr (element_type *ptr) |
| Volatile pointer constructor. More...
|
|
template<typename U , typename = typename std::enable_if< !std::is_same<T, U>::value && std::is_same<typename std::remove_cv<T>::type, U>::value>::type> |
| persistent_ptr (persistent_ptr< U > const &r) noexcept |
| Copy constructor from a different persistent_ptr<>. More...
|
|
template<typename U , typename Dummy = void, typename = typename std::enable_if< !std::is_same< typename std::remove_cv<T>::type, typename std::remove_cv<U>::type>::value && !std::is_void<U>::value, decltype(static_cast<T *>(std::declval<U *>()))>::type> |
| persistent_ptr (persistent_ptr< U > const &r) noexcept |
| Copy constructor from a different persistent_ptr<>. More...
|
|
| operator persistent_ptr< void > () const noexcept |
| Persistent pointer to void conversion operator.
|
|
pmem::detail::sp_dereference< T >::type | operator* () const noexcept |
| Dereference operator.
|
|
pmem::detail::sp_member_access< T >::type | operator-> () const noexcept |
| Member access operator.
|
|
template<typename = typename std::enable_if<!std::is_void<T>::value>> |
pmem::detail::sp_array_access< T >::type | operator[] (std::ptrdiff_t i) const noexcept |
| Array access operator. More...
|
|
persistent_ptr< T > & | operator++ () |
| Prefix increment operator.
|
|
persistent_ptr< T > | operator++ (int) |
| Postfix increment operator.
|
|
persistent_ptr< T > & | operator-- () |
| Prefix decrement operator.
|
|
persistent_ptr< T > | operator-- (int) |
| Postfix decrement operator.
|
|
persistent_ptr< T > & | operator+= (std::ptrdiff_t s) |
| Addition assignment operator.
|
|
persistent_ptr< T > & | operator-= (std::ptrdiff_t s) |
| Subtraction assignment operator.
|
|
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y *, T *>::value>::type> |
persistent_ptr< T > & | operator= (persistent_ptr< Y > const &r) |
| Converting assignment operator from a different persistent_ptr<>. More...
|
|
void | persist (pool_base &pop) |
| Persists the content of the underlying object. More...
|
|
void | persist (void) |
| Persists what the persistent pointer points to. More...
|
|
void | flush (pool_base &pop) |
| Flushes what the persistent pointer points to. More...
|
|
void | flush (void) |
| Flushes what the persistent pointer points to. More...
|
|
element_type * | get () const noexcept |
| Get the direct pointer. More...
|
|
| persistent_ptr_base () noexcept |
| Default constructor, zeroes the PMEMoid.
|
|
| persistent_ptr_base (PMEMoid oid) noexcept |
| PMEMoid constructor. More...
|
|
| persistent_ptr_base (persistent_ptr_base &&r) noexcept |
| Move constructor.
|
|
| persistent_ptr_base () noexcept |
| Default constructor, zeroes the PMEMoid.
|
|
| persistent_ptr_base (PMEMoid oid) noexcept |
| PMEMoid constructor. More...
|
|
| persistent_ptr_base (persistent_ptr_base &&r) noexcept |
| Move constructor.
|
|
persistent_ptr_base & | operator= (persistent_ptr_base &&r) |
| Move assignment operator.
|
|
persistent_ptr_base & | operator= (persistent_ptr_base const &r) |
| Assignment operator. More...
|
|
persistent_ptr_base & | operator= (std::nullptr_t &&) |
| Nullptr move assignment operator. More...
|
|
void | swap (persistent_ptr_base &other) |
| Swaps two persistent_ptr objects of the same type. More...
|
|
const PMEMoid & | raw () const noexcept |
| Get PMEMoid encapsulated by this object. More...
|
|
PMEMoid * | raw_ptr () noexcept |
| Get pointer to PMEMoid encapsulated by this object. More...
|
|
template<typename T>
class pmem::obj::persistent_ptr< T >
Persistent pointer class.
persistent_ptr implements a smart ptr. It encapsulates the PMEMoid fat pointer and provides member access, dereference and array access operators.
Template parameter type has following requirements:
Even if all of the above requirements are met, type representation may vary depending on ABI and compiler optimizations (as stated in [class.mem]: "the order of allocation of non-static data members with different access control is unspecified"). To enforce the same layout for all ABIs and optimization levels type should satisfy StandardLayoutType requirement.If pointer is used with array type, additional requirement is:
- Element type must be default constructible
The pointer is not designed to work with polymorphic types, as they have runtime RTTI info embedded, which is implementation specific and thus not consistently rebuildable. Such constructs as polymorphic members or members of a union defined within a class held in a pointer will also yield undefined behavior.C++ standard states that lifetime of an object is a runtime property [basic.lifetime]. Conditions which must be fulfilled for object's lifetime to begin, imply that using any non-trivially constructible object with pointer is undefined behaviour. This is being partially addressed by the following proposal:
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/bk8esqk-QooAnother caveat is that snapshotting elements in a transaction and performing rollback uses memcpy internally. Using memcpy on an object in C++ is allowed by the standard only if the type satisfies TriviallyCopyable requirement.
This type does NOT manage the life-cycle of the object. The typical usage example would be:
#include <fcntl.h>
void
persistent_ptr_example()
{
struct compound_type {
void
set_some_variable(int val)
{
some_variable = val;
}
int some_variable;
double some_other_variable;
};
struct root {
persistent_ptr<compound_type> comp;
} proot;
proot.comp = make_persistent<compound_type>();
proot.comp->set_some_variable(12);
proot.comp->some_other_variable = 2.3;
});
compound_type tmp = *proot.comp;
(void)tmp;
proot.comp->some_variable = 12;
}
static void run(obj::pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:694
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:694
Persistent_ptr transactional allocation functions for objects.
Main libpmemobj namespace.
Definition: allocation_flag.hpp:18
Persistent smart pointer.
C++ pmemobj transactions.
Casting to persistent_ptr_base can be easily done from any persistent_ptr<T> objects, but when casting between convertible objects be advised to use constructors or operator= specified for such conversion, see:
Below you can find an example how to and how NOT to cast persistent_ptr's:
#include <iostream>
void
persistent_ptr_conversion_example()
{
struct root {
persistent_ptr<int> pfoo;
};
persistent_ptr<double> dptr = i_ptr_base.raw();
std::cout << *dptr;
persistent_ptr<int> iptr_nonbase = i_ptr_base.raw();
std::cout << *iptr_nonbase;
persistent_ptr<int> i_ptr = make_persistent<int>(10);
std::cout << i_ptr_ref->raw().off;
});
struct A {
uint64_t a;
};
struct B {
uint64_t b;
};
struct C : public A, public B {
uint64_t c;
};
auto cptr = make_persistent<C>();
persistent_ptr<B> bptr = cptr;
std::cout << (bptr->b ==
cptr->b);
persistent_ptr<B> bptr2;
bptr2 = cptr;
std::cout << (bptr2->b == cptr->b);
persistent_ptr<B> bptr3 = static_cast<persistent_ptr<B>>(cptr);
std::cout << (bptr3->b == cptr->b);
});
}
persistent_ptr_base() noexcept
Default constructor, zeroes the PMEMoid.
Definition: persistent_ptr_base.hpp:47
Base class for persistent_ptr.