11 #ifndef LIBPMEMOBJ_CPP_MAKE_PERSISTENT_HPP
12 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_HPP
21 #include <libpmemobj/tx_base.h>
48 template <
typename T,
typename... Args>
49 typename detail::pp_if_not_array<T>::type
52 if (pmemobj_tx_stage() != TX_STAGE_WORK)
54 "refusing to allocate memory outside of transaction scope");
57 pmemobj_tx_xalloc(
sizeof(T), detail::type_num<T>(), flag.value);
62 "Failed to allocate persistent memory object")
63 .with_pmemobj_errormsg();
66 "Failed to allocate persistent memory object")
67 .with_pmemobj_errormsg();
70 detail::create<T, Args...>(ptr.
get(), std::forward<Args>(args)...);
90 template <
typename T,
typename... Args>
91 typename std::enable_if<
92 !detail::is_first_arg_same<allocation_flag, Args...>::value,
97 std::forward<Args>(args)...);
117 template <
typename T>
121 if (pmemobj_tx_stage() != TX_STAGE_WORK)
123 "refusing to free memory outside of transaction scope");
132 detail::destroy<T>(*ptr);
134 if (pmemobj_tx_free(*ptr.
raw_ptr()) != 0)
136 "failed to delete persistent memory object")
137 .with_pmemobj_errormsg();
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:152
element_type * get() const noexcept
Get the direct pointer.
Definition: persistent_ptr.hpp:478
Custom transaction error class.
Definition: pexceptions.hpp:119
Custom transaction error class.
Definition: pexceptions.hpp:158
Custom out of memory error class.
Definition: pexceptions.hpp:138
Custom transaction error class.
Definition: pexceptions.hpp:176
Commonly used functionality.
Functions for destroying arrays.
Persistent_ptr allocation functions for arrays.
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:119
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:50
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.