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);
207 template <
typename T>
211 typedef typename detail::pp_array_type<T>::type I;
213 if (pmemobj_tx_stage() != TX_STAGE_WORK)
215 "refusing to free memory outside of transaction scope");
224 auto data = ptr.get();
226 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
228 data[
static_cast<std::ptrdiff_t
>(N) - 1 - i]);
230 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
232 "failed to delete persistent memory object")
233 .with_pmemobj_errormsg();
253 template <
typename T>
257 typedef typename detail::pp_array_type<T>::type I;
258 enum { N = detail::pp_array_elems<T>::elems };
260 if (pmemobj_tx_stage() != TX_STAGE_WORK)
262 "refusing to free memory outside of transaction scope");
271 auto data = ptr.get();
273 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
275 data[
static_cast<std::ptrdiff_t
>(N) - 1 - i]);
277 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
279 "failed to delete persistent memory object")
280 .with_pmemobj_errormsg();