38 #ifndef LIBPMEMOBJ_CPP_ALLOCATOR_HPP 39 #define LIBPMEMOBJ_CPP_ALLOCATOR_HPP 46 #include <libpmemobj/tx_base.h> 67 using reference = value_type &;
68 using const_reference =
const value_type &;
92 typename =
typename std::enable_if<
93 std::is_convertible<U *, T *>::value>::type>
110 detail::conditional_add_to_tx(
p.get());
111 new (static_cast<void *>(
p.get())) value_type(t);
122 template <
typename... Args>
126 detail::conditional_add_to_tx(
p.get());
127 new (static_cast<void *>(
p.get()))
128 value_type(std::forward<Args>(args)...);
142 if (pmemobj_tx_stage() == TX_STAGE_WORK) {
143 pmemobj_tx_add_range_direct((
void *)
p.get(),
sizeof(
p));
146 detail::destroy<value_type>(*
p);
160 using value_type = void;
184 template <
typename U>
196 template <
typename T>
202 using value_type = T;
205 using size_type = std::size_t;
206 using bool_type = bool;
236 template <
typename U,
237 typename =
typename std::enable_if<
238 std::is_convertible<U *, T *>::value>::type>
254 if (pmemobj_tx_stage() != TX_STAGE_WORK)
256 "refusing to allocate memory outside of transaction scope");
259 return pmemobj_tx_alloc(
sizeof(value_type) * cnt,
260 detail::type_num<T>());
273 if (pmemobj_tx_stage() != TX_STAGE_WORK)
275 "refusing to free memory outside of transaction scope");
277 if (pmemobj_tx_free(*
p.raw_ptr()) != 0)
279 "failed to delete persistent memory object");
290 return PMEMOBJ_MAX_ALLOC_SIZE /
sizeof(value_type);
303 using value_type = void;
306 using reference = value_type;
307 using const_reference =
const value_type;
308 using size_type = std::size_t;
309 using bool_type = bool;
339 template <
typename U>
354 if (pmemobj_tx_stage() != TX_STAGE_WORK)
356 "refusing to allocate memory outside of transaction scope");
359 return pmemobj_tx_alloc(1 * cnt, 0);
372 if (pmemobj_tx_stage() != TX_STAGE_WORK)
374 "refusing to free memory outside of transaction scope");
376 if (pmemobj_tx_free(
p.raw()) != 0)
378 "failed to delete persistent memory object");
389 return PMEMOBJ_MAX_ALLOC_SIZE;
398 template <
typename T,
typename T2>
410 template <
typename T,
typename OtherAllocator>
424 template <
typename T,
typename Policy = standard_alloc_policy<T>,
425 typename Traits =
object_traits<T>>
431 using AllocationPolicy = Policy;
432 using TTraits = Traits;
438 using size_type =
typename AllocationPolicy::size_type;
439 using pointer =
typename AllocationPolicy::pointer;
440 using value_type =
typename AllocationPolicy::value_type;
445 template <
typename U>
472 template <
typename U>
480 template <
typename U,
typename P,
typename T2>
482 : Policy(rhs), Traits(rhs)
496 template <
typename T,
typename P,
typename Tr,
typename T2,
typename P2,
501 return operator==(static_cast<const P &>(lhs),
502 static_cast<const P2 &>(rhs));
514 template <
typename T,
typename P,
typename Tr,
typename OtherAllocator>
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:400
pointer allocate(size_type cnt, const_pointer=0)
Allocate storage for cnt bytes.
Definition: allocator.hpp:352
(EXPERIMENTAL) Encapsulates the information about the persistent memory allocation model using PMDK's...
Definition: allocator.hpp:426
standard_alloc_policy(standard_alloc_policy< U > const &)
Type converting constructor.
Definition: allocator.hpp:239
allocator(allocator const &rhs)
Explicit copy constructor.
Definition: allocator.hpp:465
Persistent pointer class.
Definition: common.hpp:119
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:370
allocator(allocator< U, P, T2 > const &rhs)
Type converting constructor.
Definition: allocator.hpp:481
object_traits(object_traits< U > const &)
Type converting constructor.
Definition: allocator.hpp:94
standard_alloc_policy()=default
Defaulted constructor.
standard_alloc_policy(standard_alloc_policy const &)
Explicit copy constructor.
Definition: allocator.hpp:229
Convenience extensions for the resides on pmem property template.
~standard_alloc_policy()=default
Defaulted destructor.
void destroy(pointer p)
Destroy an object based on a pointer.
Definition: allocator.hpp:139
Functions for destroying arrays.
Commonly used functionality.
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:271
Rebind to a different type.
Definition: allocator.hpp:74
object_traits(object_traits< U > const &)
Type converting constructor.
Definition: allocator.hpp:185
The allocation policy template for a given type.
Definition: allocator.hpp:197
object_traits()=default
Defaulted constructor.
~object_traits()=default
Defaulted destructor.
standard_alloc_policy(standard_alloc_policy const &)
Explicit copy constructor.
Definition: allocator.hpp:332
allocator(allocator< U > const &)
Type converting constructor.
Definition: allocator.hpp:473
Rebind to a different type.
Definition: allocator.hpp:446
~allocator()=default
Defaulted destructor.
Rebind to a different type.
Definition: allocator.hpp:212
Persistent smart pointer.
pointer allocate(size_type cnt, const_void_pointer=0)
Allocate storage for cnt objects of type T.
Definition: allocator.hpp:252
Custom transaction error class.
Definition: pexceptions.hpp:94
Resides on pmem class.
Definition: p.hpp:64
size_type max_size() const
The largest value that can meaningfully be passed to allocate().
Definition: allocator.hpp:387
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:516
Custom transaction error class.
Definition: pexceptions.hpp:104
Encapsulates object specific allocator functionality.
Definition: allocator.hpp:59
void construct(pointer p, Args &&... args)
Create an object at a specific address.
Definition: allocator.hpp:124
size_type max_size() const
The largest value that can meaningfully be passed to allocate().
Definition: allocator.hpp:288
void construct(pointer p, const_reference t)
Create an object at a specific address.
Definition: allocator.hpp:107
allocator()=default
Defaulted constructor.
standard_alloc_policy(standard_alloc_policy< U > const &)
Type converting constructor.
Definition: allocator.hpp:340