11 #ifndef LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_HPP
12 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_HPP
21 #include <libpmemobj/tx_base.h>
49 typename detail::pp_if_array<T>::type
52 typedef typename detail::pp_array_type<T>::type I;
60 static_cast<std::size_t
>(std::numeric_limits<ptrdiff_t>::max()));
62 if (pmemobj_tx_stage() != TX_STAGE_WORK)
64 "refusing to allocate memory outside of transaction scope");
67 sizeof(I) * N, detail::type_num<I>(), flag.value);
72 "Failed to allocate persistent memory array")
73 .with_pmemobj_errormsg();
76 "Failed to allocate persistent memory array")
77 .with_pmemobj_errormsg();
84 auto data = ptr.
get();
94 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
95 detail::create<I>(data + i);
115 template <
typename T>
116 typename detail::pp_if_size_array<T>::type
119 typedef typename detail::pp_array_type<T>::type I;
120 enum { N = detail::pp_array_elems<T>::elems };
122 if (pmemobj_tx_stage() != TX_STAGE_WORK)
124 "refusing to allocate memory outside of transaction scope");
127 sizeof(I) * N, detail::type_num<I>(), flag.value);
129 if (ptr ==
nullptr) {
132 "Failed to allocate persistent memory array")
133 .with_pmemobj_errormsg();
136 "Failed to allocate persistent memory array")
137 .with_pmemobj_errormsg();
144 auto data = ptr.
get();
154 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
155 detail::create<I>(data + i);
178 template <
typename T>
182 typedef typename detail::pp_array_type<T>::type I;
184 if (pmemobj_tx_stage() != TX_STAGE_WORK)
186 "refusing to free memory outside of transaction scope");
195 auto data = ptr.get();
197 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
199 data[
static_cast<std::ptrdiff_t
>(N) - 1 - i]);
201 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
203 "failed to delete persistent memory object")
204 .with_pmemobj_errormsg();
224 template <
typename T>
228 typedef typename detail::pp_array_type<T>::type I;
229 enum { N = detail::pp_array_elems<T>::elems };
231 if (pmemobj_tx_stage() != TX_STAGE_WORK)
233 "refusing to free memory outside of transaction scope");
242 auto data = ptr.get();
244 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
246 data[
static_cast<std::ptrdiff_t
>(N) - 1 - i]);
248 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
250 "failed to delete persistent memory object")
251 .with_pmemobj_errormsg();
allocation_flag - defines flags which can be passed to make_persistent
Compile time type check for make_persistent.
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.
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.