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 memory outside of transaction scope");
93 pmemobj_tx_alloc(
sizeof(I) * N, detail::type_num<I>());
97 "failed to allocate persistent memory array");
107 for (std::size_t i = 0; i < N; ++i)
108 detail::create<I>(ptr.
get() + i);
126 template <
typename T>
127 typename detail::pp_if_size_array<T>::type
130 typedef typename detail::pp_array_type<T>::type I;
131 enum { N = detail::pp_array_elems<T>::elems };
133 if (pmemobj_tx_stage() != TX_STAGE_WORK)
135 "refusing to allocate memory outside of transaction scope");
138 pmemobj_tx_alloc(
sizeof(I) * N, detail::type_num<I>());
142 "failed to allocate persistent memory array");
152 for (std::size_t i = 0; i < N; ++i)
153 detail::create<I>(ptr.
get() + i);
173 template <
typename T>
177 typedef typename detail::pp_array_type<T>::type I;
179 if (pmemobj_tx_stage() != TX_STAGE_WORK)
181 "refusing to free memory outside of transaction scope");
186 for (std::size_t i = 0; i < N; ++i)
187 detail::destroy<I>(ptr[N - 1 - i]);
189 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
191 "failed to delete persistent memory object");
208 template <
typename T>
212 typedef typename detail::pp_array_type<T>::type I;
213 enum { N = detail::pp_array_elems<T>::elems };
215 if (pmemobj_tx_stage() != TX_STAGE_WORK)
217 "refusing to free memory outside of transaction scope");
222 for (std::size_t i = 0; i < N; ++i)
223 detail::destroy<I>(ptr[N - 1 - i]);
225 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
227 "failed to delete persistent memory object");
Custom transaction error class.
Definition: pexceptions.hpp:84
Persistent pointer class.
Definition: common.hpp:72
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:109
detail::pp_if_not_array< T >::type make_persistent(Args &&... args)
Transactionally allocate and construct an object of type T.
Definition: make_persistent.hpp:75
Functions for destroying arrays.
Commonly used functionality.
Compile time type check for make_persistent.
Custom transaction error class.
Definition: pexceptions.hpp:94
Custom transaction error class.
Definition: pexceptions.hpp:104
Definition: allocator.hpp:48
element_type * get() const noexcept
Get a direct pointer.
Definition: persistent_ptr_base.hpp:286