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);
204 template <
typename T>
208 typedef typename detail::pp_array_type<T>::type I;
210 if (pmemobj_tx_stage() != TX_STAGE_WORK)
212 "refusing to free memory outside of transaction scope");
221 auto data = ptr.get();
223 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
225 data[static_cast<std::ptrdiff_t>(N) - 1 - i]);
227 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
229 "failed to delete persistent memory object")
230 .with_pmemobj_errormsg();
247 template <
typename T>
251 typedef typename detail::pp_array_type<T>::type I;
252 enum { N = detail::pp_array_elems<T>::elems };
254 if (pmemobj_tx_stage() != TX_STAGE_WORK)
256 "refusing to free memory outside of transaction scope");
265 auto data = ptr.get();
267 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(N); ++i)
269 data[static_cast<std::ptrdiff_t>(N) - 1 - i]);
271 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
273 "failed to delete persistent memory object")
274 .with_pmemobj_errormsg();
Custom transaction error class.
Definition: pexceptions.hpp:128
Persistent pointer class.
Definition: common.hpp:125
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:145
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.
Custom out of memory error class.
Definition: pexceptions.hpp:146
allocation_flag - defines flags which can be passed to make_persistent
Custom transaction error class.
Definition: pexceptions.hpp:167
Custom transaction error class.
Definition: pexceptions.hpp:185
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: allocation_flag.hpp:43
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