12 #ifndef LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_HPP
13 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_HPP
22 #include <libpmemobj/tx_base.h>
53 typename detail::pp_if_array<T>::type
56 typedef typename detail::pp_array_type<T>::type I;
64 static_cast<std::size_t
>(std::numeric_limits<ptrdiff_t>::max()));
66 if (pmemobj_tx_stage() != TX_STAGE_WORK)
68 "refusing to allocate memory outside of transaction scope");
71 sizeof(I) * N, detail::type_num<I>(), flag.value);
74 const char *msg =
"Failed to allocate persistent memory array";
87 auto data = ptr.
get();
97 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
98 detail::create<I>(data + i);
121 template <
typename T>
122 typename detail::pp_if_size_array<T>::type
125 typedef typename detail::pp_array_type<T>::type I;
126 enum { N = detail::pp_array_elems<T>::elems };
128 if (pmemobj_tx_stage() != TX_STAGE_WORK)
130 "refusing to allocate memory outside of transaction scope");
133 sizeof(I) * N, detail::type_num<I>(), flag.value);
135 if (ptr ==
nullptr) {
136 const char *msg =
"Failed to allocate persistent memory array";
149 auto data = ptr.
get();
159 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
160 detail::create<I>(data + i);
184 template <
typename T>
188 typedef typename detail::pp_array_type<T>::type I;
190 if (pmemobj_tx_stage() != TX_STAGE_WORK)
192 "refusing to free memory outside of transaction scope");
201 auto data = ptr.get();
203 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
205 data[
static_cast<std::ptrdiff_t
>(N) - 1 - i]);
207 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
210 "failed to delete persistent memory object");
231 template <
typename T>
235 typedef typename detail::pp_array_type<T>::type I;
236 enum { N = detail::pp_array_elems<T>::elems };
238 if (pmemobj_tx_stage() != TX_STAGE_WORK)
240 "refusing to free 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)
258 "failed to delete persistent memory object");
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:153
element_type * get() const noexcept
Get the direct pointer.
Definition: persistent_ptr.hpp:479
Custom transaction error class.
Definition: pexceptions.hpp:132
Custom transaction error class.
Definition: pexceptions.hpp:156
Custom out of memory error class.
Definition: pexceptions.hpp:144
Custom transaction error class.
Definition: pexceptions.hpp:167
Commonly used functionality.
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:126
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:54
Functions for lifetime management.
ExcT exception_with_errormsg(Args &&... args)
Generic error message decorator for pmemobj-based exceptions.
Definition: pexceptions.hpp:69
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.