40 #ifndef LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_HPP
41 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_HPP
48 #include <libpmemobj/tx_base.h>
75 typename detail::pp_if_array<T>::type
78 typedef typename detail::pp_array_type<T>::type I;
86 static_cast<std::size_t
>(std::numeric_limits<ptrdiff_t>::max()));
88 if (pmemobj_tx_stage() != TX_STAGE_WORK)
90 "refusing to allocate "
91 "memory outside of transaction scope");
94 pmemobj_tx_alloc(
sizeof(I) * N, detail::type_num<I>());
98 "persistent memory array");
104 auto data = ptr.get();
114 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
115 detail::create<I>(data + i);
133 template <
typename T>
134 typename detail::pp_if_size_array<T>::type
137 typedef typename detail::pp_array_type<T>::type I;
138 enum { N = detail::pp_array_elems<T>::elems };
140 if (pmemobj_tx_stage() != TX_STAGE_WORK)
142 "refusing to allocate "
143 "memory outside of transaction scope");
146 pmemobj_tx_alloc(
sizeof(I) * N, detail::type_num<I>());
150 "persistent memory array");
156 auto data = ptr.get();
166 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
167 detail::create<I>(data + i);
187 template <
typename T>
191 typedef typename detail::pp_array_type<T>::type I;
193 if (pmemobj_tx_stage() != TX_STAGE_WORK)
196 "memory outside of transaction scope");
205 auto data = ptr.get();
207 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
209 data[
static_cast<std::ptrdiff_t
>(N) - 1 - i]);
211 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
213 "persistent memory object");
230 template <
typename T>
234 typedef typename detail::pp_array_type<T>::type I;
235 enum { N = detail::pp_array_elems<T>::elems };
237 if (pmemobj_tx_stage() != TX_STAGE_WORK)
240 "memory outside of transaction scope");
249 auto data = ptr.get();
251 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
253 data[
static_cast<std::ptrdiff_t
>(N) - 1 - i]);
255 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
257 "persistent memory object");