40 #ifndef LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_HPP
41 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_HPP
50 #include <libpmemobj/tx_base.h>
78 typename detail::pp_if_array<T>::type
81 typedef typename detail::pp_array_type<T>::type I;
89 static_cast<std::size_t
>(std::numeric_limits<ptrdiff_t>::max()));
91 if (pmemobj_tx_stage() != TX_STAGE_WORK)
93 "refusing to allocate memory outside of transaction scope");
96 sizeof(I) * N, detail::type_num<I>(), flag.value);
101 "Failed to allocate persistent memory array")
102 .with_pmemobj_errormsg();
105 "Failed to allocate persistent memory array")
106 .with_pmemobj_errormsg();
113 auto data = ptr.get();
123 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
124 detail::create<I>(data + i);
144 template <
typename T>
145 typename detail::pp_if_size_array<T>::type
148 typedef typename detail::pp_array_type<T>::type I;
149 enum { N = detail::pp_array_elems<T>::elems };
151 if (pmemobj_tx_stage() != TX_STAGE_WORK)
153 "refusing to allocate memory outside of transaction scope");
156 sizeof(I) * N, detail::type_num<I>(), flag.value);
158 if (ptr ==
nullptr) {
161 "Failed to allocate persistent memory array")
162 .with_pmemobj_errormsg();
165 "Failed to allocate persistent memory array")
166 .with_pmemobj_errormsg();
173 auto data = ptr.get();
183 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
184 detail::create<I>(data + i);
204 template <
typename T>
208 typedef typename detail::pp_array_type<T>::type I;
210 if (pmemobj_tx_stage() != TX_STAGE_WORK)
212 "refusing to free memory outside of transaction scope");
221 auto data = ptr.get();
223 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
225 data[
static_cast<std::ptrdiff_t
>(N) - 1 - i]);
227 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
229 "failed to delete persistent memory object")
230 .with_pmemobj_errormsg();
247 template <
typename T>
251 typedef typename detail::pp_array_type<T>::type I;
252 enum { N = detail::pp_array_elems<T>::elems };
254 if (pmemobj_tx_stage() != TX_STAGE_WORK)
256 "refusing to free memory outside of transaction scope");
265 auto data = ptr.get();
267 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
269 data[
static_cast<std::ptrdiff_t
>(N) - 1 - i]);
271 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
273 "failed to delete persistent memory object")
274 .with_pmemobj_errormsg();