40 #ifndef LIBPMEMOBJ_CPP_MAKE_PERSISTENT_HPP
41 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_HPP
47 #include "libpmemobj/tx_base.h"
73 template <
typename T,
typename... Args>
74 typename detail::pp_if_not_array<T>::type
75 make_persistent(Args &&... args)
77 if (pmemobj_tx_stage() != TX_STAGE_WORK)
78 throw transaction_scope_error(
79 "refusing to allocate "
80 "memory outside of transaction scope");
82 persistent_ptr<T> ptr =
83 pmemobj_tx_alloc(
sizeof(T), detail::type_num<T>());
86 throw transaction_alloc_error(
"failed to allocate "
87 "persistent memory object");
89 detail::create<T, Args...>(ptr.get(), std::forward<Args>(args)...);
108 template <
typename T>
110 delete_persistent(
typename detail::pp_if_not_array<T>::type ptr)
112 if (pmemobj_tx_stage() != TX_STAGE_WORK)
113 throw transaction_scope_error(
115 "memory outside of transaction scope");
124 detail::destroy<T>(*ptr);
126 if (pmemobj_tx_free(*ptr.raw_ptr()) != 0)
127 throw transaction_free_error(
"failed to delete "
128 "persistent memory object");
Functions for destroying arrays.
Commonly used functionality.
Compile time type check for make_persistent.
Definition: allocator.hpp:48