9 #ifndef LIBPMEMOBJ_CPP_ALLOCATOR_HPP
10 #define LIBPMEMOBJ_CPP_ALLOCATOR_HPP
17 #include <libpmemobj/tx_base.h>
38 using reference = value_type &;
39 using const_reference =
const value_type &;
63 typename =
typename std::enable_if<
64 std::is_convertible<U *, T *>::value>::type>
84 if (pmemobj_tx_stage() != TX_STAGE_WORK)
86 "construct is called outside of transaction scope");
89 detail::conditional_add_to_tx(
p.get());
90 new (
static_cast<void *
>(
p.get())) value_type(t);
105 template <
typename... Args>
109 if (pmemobj_tx_stage() != TX_STAGE_WORK)
111 "construct is called outside of transaction scope");
113 detail::conditional_add_to_tx(
p.get());
114 new (
static_cast<void *
>(
p.get()))
115 value_type(std::forward<Args>(args)...);
129 if (pmemobj_tx_stage() == TX_STAGE_WORK) {
130 pmemobj_tx_add_range_direct((
void *)
p.get(),
sizeof(
p));
133 detail::destroy<value_type>(*
p);
147 using value_type = void;
171 template <
typename U>
183 template <
typename T>
189 using value_type = T;
192 using size_type = std::size_t;
193 using bool_type = bool;
223 template <
typename U,
224 typename =
typename std::enable_if<
225 std::is_convertible<U *, T *>::value>::type>
244 if (pmemobj_tx_stage() != TX_STAGE_WORK)
246 "refusing to allocate memory outside of transaction scope");
249 pointer ptr = pmemobj_tx_alloc(
sizeof(value_type) * cnt,
250 detail::type_num<value_type>());
252 if (ptr ==
nullptr) {
253 if (errno == ENOMEM) {
255 "Failed to allocate persistent memory object")
256 .with_pmemobj_errormsg();
259 "Failed to allocate persistent memory object")
260 .with_pmemobj_errormsg();
277 if (pmemobj_tx_stage() != TX_STAGE_WORK)
279 "refusing to free memory outside of transaction scope");
281 if (pmemobj_tx_free(*
p.raw_ptr()) != 0)
283 "failed to delete persistent memory object")
284 .with_pmemobj_errormsg();
295 return PMEMOBJ_MAX_ALLOC_SIZE /
sizeof(value_type);
308 using value_type = void;
311 using reference = value_type;
312 using const_reference =
const value_type;
313 using size_type = std::size_t;
314 using bool_type = bool;
344 template <
typename U>
359 if (pmemobj_tx_stage() != TX_STAGE_WORK)
361 "refusing to allocate memory outside of transaction scope");
364 pointer ptr = pmemobj_tx_alloc(1 * cnt, 0);
366 if (ptr ==
nullptr) {
367 if (errno == ENOMEM) {
369 "Failed to allocate persistent memory object")
370 .with_pmemobj_errormsg();
373 "Failed to allocate persistent memory object")
374 .with_pmemobj_errormsg();
391 if (pmemobj_tx_stage() != TX_STAGE_WORK)
393 "refusing to free memory outside of transaction scope");
395 if (pmemobj_tx_free(
p.raw()) != 0)
397 "failed to delete persistent memory object")
398 .with_pmemobj_errormsg();
409 return PMEMOBJ_MAX_ALLOC_SIZE;
418 template <
typename T,
typename T2>
430 template <
typename T,
typename OtherAllocator>
444 template <
typename T,
typename Policy = standard_alloc_policy<T>,
445 typename Traits =
object_traits<T>>
451 using AllocationPolicy = Policy;
452 using TTraits = Traits;
458 using size_type =
typename AllocationPolicy::size_type;
459 using pointer =
typename AllocationPolicy::pointer;
460 using value_type =
typename AllocationPolicy::value_type;
465 template <
typename U>
492 template <
typename U>
500 template <
typename U,
typename P,
typename T2>
502 : Policy(rhs), Traits(rhs)
516 template <
typename T,
typename P,
typename Tr,
typename T2,
typename P2,
521 return operator==(
static_cast<const P &
>(lhs),
522 static_cast<const P2 &
>(rhs));
534 template <
typename T,
typename P,
typename Tr,
typename OtherAllocator>
(EXPERIMENTAL) Encapsulates the information about the persistent memory allocation model using PMDK's...
Definition: allocator.hpp:446
allocator()=default
Defaulted constructor.
~allocator()=default
Defaulted destructor.
allocator(allocator< U, P, T2 > const &rhs)
Type converting constructor.
Definition: allocator.hpp:501
allocator(allocator< U > const &)
Type converting constructor.
Definition: allocator.hpp:493
allocator(allocator const &rhs)
Copy constructor.
Definition: allocator.hpp:485
object_traits()=default
Defaulted constructor.
~object_traits()=default
Defaulted destructor.
object_traits(object_traits< U > const &)
Type converting constructor.
Definition: allocator.hpp:172
Encapsulates object specific allocator functionality.
Definition: allocator.hpp:30
object_traits()=default
Defaulted constructor.
object_traits(object_traits< U > const &)
Type converting constructor.
Definition: allocator.hpp:65
void destroy(pointer p)
Destroy an object based on a pointer.
Definition: allocator.hpp:126
void construct(pointer p, const_reference t)
Create an object at a specific address.
Definition: allocator.hpp:82
~object_traits()=default
Defaulted destructor.
void construct(pointer p, Args &&... args)
Create an object at a specific address.
Definition: allocator.hpp:107
Resides on pmem class.
Definition: p.hpp:35
persistent_ptr const void specialization.
Definition: persistent_ptr.hpp:88
Persistent pointer class.
Definition: persistent_ptr.hpp:152
size_type max_size() const
The largest value that can meaningfully be passed to allocate().
Definition: allocator.hpp:407
standard_alloc_policy(standard_alloc_policy< U > const &)
Type converting constructor.
Definition: allocator.hpp:345
standard_alloc_policy(standard_alloc_policy const &)
Explicit copy constructor.
Definition: allocator.hpp:337
pointer allocate(size_type cnt, const_pointer=0)
Allocate storage for cnt bytes.
Definition: allocator.hpp:357
~standard_alloc_policy()=default
Defaulted destructor.
standard_alloc_policy()=default
Defaulted constructor.
void deallocate(pointer p, size_type=0)
Deallocates storage pointed to p, which must be a value returned by a previous call to allocate that ...
Definition: allocator.hpp:389
The allocation policy template for a given type.
Definition: allocator.hpp:184
size_type max_size() const
The largest value that can meaningfully be passed to allocate().
Definition: allocator.hpp:293
~standard_alloc_policy()=default
Defaulted destructor.
pointer allocate(size_type cnt, const_void_pointer=0)
Allocate storage for cnt objects of type T.
Definition: allocator.hpp:242
standard_alloc_policy()=default
Defaulted constructor.
void deallocate(pointer p, size_type=0)
Deallocates storage pointed to p, which must be a value returned by a previous call to allocate that ...
Definition: allocator.hpp:275
standard_alloc_policy(standard_alloc_policy< U > const &)
Type converting constructor.
Definition: allocator.hpp:226
standard_alloc_policy(standard_alloc_policy const &)
Explicit copy constructor.
Definition: allocator.hpp:216
Custom transaction error class.
Definition: pexceptions.hpp:119
Custom transaction error class.
Definition: pexceptions.hpp:158
Custom out of memory error class.
Definition: pexceptions.hpp:138
Custom transaction error class.
Definition: pexceptions.hpp:176
Commonly used functionality.
Functions for destroying arrays.
bool operator!=(const allocator< T, P, Tr > &lhs, const OtherAllocator &rhs)
Determines if memory from another allocator can be deallocated from this one.
Definition: allocator.hpp:536
bool operator==(standard_alloc_policy< T > const &, standard_alloc_policy< T2 > const &)
Determines if memory from another allocator can be deallocated from this one.
Definition: allocator.hpp:420
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Persistent smart pointer.
Convenience extensions for the resides on pmem property template.
Rebind to a different type.
Definition: allocator.hpp:466
Rebind to a different type.
Definition: allocator.hpp:45
Rebind to a different type.
Definition: allocator.hpp:199