12 #ifndef LIBPMEMOBJ_CPP_MAKE_PERSISTENT_HPP
13 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_HPP
22 #include <libpmemobj/tx_base.h>
52 template <
typename T,
typename... Args>
53 typename detail::pp_if_not_array<T>::type
56 if (pmemobj_tx_stage() != TX_STAGE_WORK)
58 "refusing to allocate memory outside of transaction scope");
61 pmemobj_tx_xalloc(
sizeof(T), detail::type_num<T>(), flag.value);
64 const char *msg =
"Failed to allocate persistent memory object";
73 detail::create<T, Args...>(ptr.
get(), std::forward<Args>(args)...);
96 template <
typename T,
typename... Args>
97 typename std::enable_if<
98 !detail::is_first_arg_same<allocation_flag, Args...>::value,
103 std::forward<Args>(args)...);
124 template <
typename T>
128 if (pmemobj_tx_stage() != TX_STAGE_WORK)
130 "refusing to free memory outside of transaction scope");
139 detail::destroy<T>(*ptr);
141 if (pmemobj_tx_free(*ptr.
raw_ptr()) != 0)
144 "failed to delete persistent memory object");
allocation_flag - defines flags which can be passed to make_persistent
Compile time type check for make_persistent.
PMEMoid * raw_ptr() noexcept
Get pointer to PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:164
Persistent pointer class.
Definition: persistent_ptr.hpp:153
element_type * get() const noexcept
Get the direct pointer.
Definition: persistent_ptr.hpp:479
Custom transaction error class.
Definition: pexceptions.hpp:132
Custom transaction error class.
Definition: pexceptions.hpp:156
Custom out of memory error class.
Definition: pexceptions.hpp:144
Custom transaction error class.
Definition: pexceptions.hpp:167
Commonly used functionality.
void delete_persistent(typename detail::pp_if_not_array< T >::type ptr)
Transactionally free an object of type T held in a persistent_ptr.
Definition: make_persistent.hpp:126
detail::pp_if_not_array< T >::type make_persistent(allocation_flag flag, Args &&... args)
Transactionally allocate and construct an object of type T.
Definition: make_persistent.hpp:54
Functions for lifetime management.
persistent_ptr transactional allocation functions for arrays.
ExcT exception_with_errormsg(Args &&... args)
Generic error message decorator for pmemobj-based exceptions.
Definition: pexceptions.hpp:69
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Type of flag which can be passed to make_persistent.
Definition: allocation_flag.hpp:31
static allocation_flag none()
Do not change allocator behaviour.
Definition: allocation_flag.hpp:61
Helper functionality for handling variadic templates.