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();