9 #ifndef LIBPMEMOBJ_CPP_ALLOCATOR_HPP
10 #define LIBPMEMOBJ_CPP_ALLOCATOR_HPP
17 #include <libpmemobj/tx_base.h>
39 using reference = value_type &;
40 using const_reference =
const value_type &;
64 typename =
typename std::enable_if<
65 std::is_convertible<U *, T *>::value>::type>
85 if (pmemobj_tx_stage() != TX_STAGE_WORK)
87 "construct is called outside of transaction scope");
91 new (
static_cast<void *
>(
p.get())) value_type(t);
106 template <
typename... Args>
110 if (pmemobj_tx_stage() != TX_STAGE_WORK)
112 "construct is called outside of transaction scope");
115 new (
static_cast<void *
>(
p.get()))
116 value_type(std::forward<Args>(args)...);
130 if (pmemobj_tx_stage() == TX_STAGE_WORK) {
131 pmemobj_tx_add_range_direct((
void *)
p.get(),
sizeof(
p));
134 detail::destroy<value_type>(*
p);
150 using value_type = void;
174 template <
typename U>
187 template <
typename T>
193 using value_type = T;
196 using size_type = std::size_t;
197 using bool_type = bool;
227 template <
typename U,
228 typename =
typename std::enable_if<
229 std::is_convertible<U *, T *>::value>::type>
249 if (pmemobj_tx_stage() != TX_STAGE_WORK)
251 "refusing to allocate memory outside of transaction scope");
254 pointer ptr = pmemobj_tx_alloc(
sizeof(value_type) * cnt,
255 detail::type_num<value_type>());
257 if (ptr ==
nullptr) {
259 "Failed to allocate persistent memory object";
260 if (errno == ENOMEM) {
286 if (pmemobj_tx_stage() != TX_STAGE_WORK)
288 "refusing to free memory outside of transaction scope");
290 if (pmemobj_tx_free(*
p.raw_ptr()) != 0)
293 "failed to delete persistent memory object");
304 return PMEMOBJ_MAX_ALLOC_SIZE /
sizeof(value_type);
318 using value_type = void;
321 using reference = value_type;
322 using const_reference =
const value_type;
323 using size_type = std::size_t;
324 using bool_type = bool;
354 template <
typename U>
373 if (pmemobj_tx_stage() != TX_STAGE_WORK)
375 "refusing to allocate memory outside of transaction scope");
378 pointer ptr = pmemobj_tx_alloc(1 * cnt, 0);
380 if (ptr ==
nullptr) {
382 "Failed to allocate persistent memory object";
383 if (errno == ENOMEM) {
409 if (pmemobj_tx_stage() != TX_STAGE_WORK)
411 "refusing to free memory outside of transaction scope");
413 if (pmemobj_tx_free(
p.raw()) != 0)
416 "failed to delete persistent memory object");
427 return PMEMOBJ_MAX_ALLOC_SIZE;
437 template <
typename T,
typename T2>
450 template <
typename T,
typename OtherAllocator>
465 template <
typename T,
typename Policy = standard_alloc_policy<T>,
466 typename Traits =
object_traits<T>>
472 using AllocationPolicy = Policy;
473 using TTraits = Traits;
479 using size_type =
typename AllocationPolicy::size_type;
480 using pointer =
typename AllocationPolicy::pointer;
481 using value_type =
typename AllocationPolicy::value_type;
486 template <
typename U>
513 template <
typename U>
521 template <
typename U,
typename P,
typename T2>
523 : Policy(rhs), Traits(rhs)
538 template <
typename T,
typename P,
typename Tr,
typename T2,
typename P2,
543 return operator==(
static_cast<const P &
>(lhs),
544 static_cast<const P2 &
>(rhs));
557 template <
typename T,
typename P,
typename Tr,
typename OtherAllocator>
561 return !operator==(lhs, rhs);
(EXPERIMENTAL) Encapsulates the information about the persistent memory allocation model using PMDK's...
Definition: allocator.hpp:467
allocator()=default
Defaulted constructor.
~allocator()=default
Defaulted destructor.
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:559
bool operator==(const allocator< T, P, Tr > &lhs, const allocator< T2, P2, Tr2 > &rhs)
Determines if memory from another allocator can be deallocated from this one.
Definition: allocator.hpp:541
allocator(allocator< U, P, T2 > const &rhs)
Type converting constructor.
Definition: allocator.hpp:522
allocator(allocator< U > const &)
Type converting constructor.
Definition: allocator.hpp:514
allocator(allocator const &rhs)
Copy constructor.
Definition: allocator.hpp:506
object_traits()=default
Defaulted constructor.
~object_traits()=default
Defaulted destructor.
object_traits(object_traits< U > const &)
Type converting constructor.
Definition: allocator.hpp:175
Encapsulates object specific allocator functionality.
Definition: allocator.hpp:31
object_traits()=default
Defaulted constructor.
object_traits(object_traits< U > const &)
Type converting constructor.
Definition: allocator.hpp:66
void destroy(pointer p)
Destroy an object based on a pointer.
Definition: allocator.hpp:127
void construct(pointer p, const_reference t)
Create an object at a specific address.
Definition: allocator.hpp:83
~object_traits()=default
Defaulted destructor.
void construct(pointer p, Args &&... args)
Create an object at a specific address.
Definition: allocator.hpp:108
Resides on pmem class.
Definition: p.hpp:36
persistent_ptr const void specialization.
Definition: persistent_ptr.hpp:88
Persistent pointer class.
Definition: persistent_ptr.hpp:153
size_type max_size() const
The largest value that can meaningfully be passed to allocate().
Definition: allocator.hpp:425
standard_alloc_policy(standard_alloc_policy< U > const &)
Type converting constructor.
Definition: allocator.hpp:355
standard_alloc_policy(standard_alloc_policy const &)
Explicit copy constructor.
Definition: allocator.hpp:347
pointer allocate(size_type cnt, const_pointer=0)
Allocate storage for cnt bytes.
Definition: allocator.hpp:371
~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:407
The allocation policy template for a given type.
Definition: allocator.hpp:188
size_type max_size() const
The largest value that can meaningfully be passed to allocate().
Definition: allocator.hpp:302
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:439
~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:247
bool operator==(standard_alloc_policy< T > const &, OtherAllocator const &)
Determines if memory from another allocator can be deallocated from this one.
Definition: allocator.hpp:452
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:284
standard_alloc_policy(standard_alloc_policy< U > const &)
Type converting constructor.
Definition: allocator.hpp:230
standard_alloc_policy(standard_alloc_policy const &)
Explicit copy constructor.
Definition: allocator.hpp:220
Custom transaction error class.
Definition: pexceptions.hpp:132
Custom transaction error class.
Definition: pexceptions.hpp:156
Custom out of memory error class.
Definition: pexceptions.hpp:144
Custom transaction error class.
Definition: pexceptions.hpp:167
Commonly used functionality.
Functions for lifetime management.
void conditional_add_to_tx(const T *that, std::size_t count=1, uint64_t flags=0)
Conditionally add 'count' objects to a transaction.
Definition: common.hpp:176
ExcT exception_with_errormsg(Args &&... args)
Generic error message decorator for pmemobj-based exceptions.
Definition: pexceptions.hpp:69
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:487
Rebind to a different type.
Definition: allocator.hpp:46
Rebind to a different type.
Definition: allocator.hpp:203