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);
100 "failed to allocate persistent memory array");
106 auto data = ptr.
get();
116 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
117 detail::create<I>(data + i);
137 template <
typename T>
138 typename detail::pp_if_size_array<T>::type
141 typedef typename detail::pp_array_type<T>::type I;
142 enum { N = detail::pp_array_elems<T>::elems };
144 if (pmemobj_tx_stage() != TX_STAGE_WORK)
146 "refusing to allocate memory outside of transaction scope");
149 sizeof(I) * N, detail::type_num<I>(), flag.value);
153 "failed to allocate persistent memory array");
159 auto data = ptr.
get();
169 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
170 detail::create<I>(data + i);
190 template <
typename T>
194 typedef typename detail::pp_array_type<T>::type I;
196 if (pmemobj_tx_stage() != TX_STAGE_WORK)
198 "refusing to free memory outside of transaction scope");
207 auto data = ptr.get();
209 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
211 data[static_cast<std::ptrdiff_t>(N) - 1 - i]);
213 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
215 "failed to delete persistent memory object");
232 template <
typename T>
236 typedef typename detail::pp_array_type<T>::type I;
237 enum { N = detail::pp_array_elems<T>::elems };
239 if (pmemobj_tx_stage() != TX_STAGE_WORK)
241 "refusing to free memory outside of transaction scope");
250 auto data = ptr.get();
252 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
254 data[static_cast<std::ptrdiff_t>(N) - 1 - i]);
256 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
258 "failed to delete persistent memory object");
Custom transaction error class.
Definition: pexceptions.hpp:84
Persistent pointer class.
Definition: common.hpp:119
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:138
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:79
Functions for destroying arrays.
Commonly used functionality.
Compile time type check for make_persistent.
Type of flag which can be passed to make_persistent.
Definition: allocation_flag.hpp:60
Helper functionality for handling variadic templates.
allocation_flag - defines flags which can be passed to make_persistent
Custom transaction error class.
Definition: pexceptions.hpp:94
Custom transaction error class.
Definition: pexceptions.hpp:104
element_type * get() const noexcept
Get a direct pointer.
Definition: persistent_ptr_base.hpp:286
static allocation_flag none()
Do not change allocator behaviour.
Definition: allocation_flag.hpp:90