40 #ifndef PMEMOBJ_MAKE_PERSISTENT_ARRAY_HPP 41 #define PMEMOBJ_MAKE_PERSISTENT_ARRAY_HPP 48 #include "libpmemobj/tx_base.h" 71 typename detail::pp_if_array<T>::type
74 typedef typename detail::pp_array_type<T>::type I;
76 if (pmemobj_tx_stage() != TX_STAGE_WORK)
78 "refusing to allocate " 79 "memory outside of transaction scope");
82 pmemobj_tx_alloc(
sizeof(I) * N, detail::type_num<I>());
86 "persistent memory array");
90 for (i = 0; i < N; ++i)
91 detail::create<I>(ptr.
get() + i);
93 for (std::size_t j = 1; j <= i; ++j)
94 detail::destroy<I>(ptr[i - j]);
95 pmemobj_tx_free(*ptr.
raw_ptr());
114 template <
typename T>
115 typename detail::pp_if_size_array<T>::type
118 typedef typename detail::pp_array_type<T>::type I;
119 enum { N = detail::pp_array_elems<T>::elems };
121 if (pmemobj_tx_stage() != TX_STAGE_WORK)
123 "refusing to allocate " 124 "memory outside of transaction scope");
127 pmemobj_tx_alloc(
sizeof(I) * N, detail::type_num<I>());
131 "persistent memory array");
135 for (i = 0; i < N; ++i)
136 detail::create<I>(ptr.
get() + i);
138 for (std::size_t j = 1; j <= i; ++j)
139 detail::destroy<I>(ptr[i - j]);
140 pmemobj_tx_free(*ptr.
raw_ptr());
162 template <
typename T>
166 typedef typename detail::pp_array_type<T>::type I;
168 if (pmemobj_tx_stage() != TX_STAGE_WORK)
171 "memory outside of transaction scope");
176 for (std::size_t i = 0; i < N; ++i)
177 detail::destroy<I>(ptr[N - 1 - i]);
179 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
181 "persistent memory object");
198 template <
typename T>
202 typedef typename detail::pp_array_type<T>::type I;
203 enum { N = detail::pp_array_elems<T>::elems };
205 if (pmemobj_tx_stage() != TX_STAGE_WORK)
208 "memory outside of transaction scope");
213 for (std::size_t i = 0; i < N; ++i)
214 detail::destroy<I>(ptr[N - 1 - i]);
216 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
218 "persistent memory object");
Custom transaction error class.
Definition: pexceptions.hpp:94
Persistent pointer class.
Definition: persistent_ptr.hpp:72
PMEMoid * raw_ptr() noexcept
Get pointer to PMEMoid encapsulated by this object.
Definition: persistent_ptr.hpp:289
Functions for destroying arrays.
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 persitent_ptr.
Definition: make_persistent.hpp:111
Compile time type check for make_persistent.
detail::pp_if_not_array< T >::type make_persistent(Args &&...args)
Transactionally allocate and construct an object of type T.
Definition: make_persistent.hpp:72
Definition: condition_variable.hpp:48
element_type * get() const noexcept
Get a direct pointer.
Definition: persistent_ptr.hpp:246
Custom transaction error class.
Definition: pexceptions.hpp:84