PMDK C++ bindings
1.10
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
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 return pmemobj_tx_alloc(1 * cnt, 0);
377 if (pmemobj_tx_stage() != TX_STAGE_WORK)
379 "refusing to free memory outside of transaction scope");
381 if (pmemobj_tx_free(
p.raw()) != 0)
383 "failed to delete persistent memory object")
384 .with_pmemobj_errormsg();
395 return PMEMOBJ_MAX_ALLOC_SIZE;
404 template <
typename T,
typename T2>
416 template <
typename T,
typename OtherAllocator>
430 template <
typename T,
typename Policy = standard_alloc_policy<T>,
431 typename Traits =
object_traits<T>>
437 using AllocationPolicy = Policy;
438 using TTraits = Traits;
444 using size_type =
typename AllocationPolicy::size_type;
445 using pointer =
typename AllocationPolicy::pointer;
446 using value_type =
typename AllocationPolicy::value_type;
451 template <
typename U>
478 template <
typename U>
486 template <
typename U,
typename P,
typename T2>
488 : Policy(rhs), Traits(rhs)
502 template <
typename T,
typename P,
typename Tr,
typename T2,
typename P2,
507 return operator==(
static_cast<const P &
>(lhs),
508 static_cast<const P2 &
>(rhs));
520 template <
typename T,
typename P,
typename Tr,
typename OtherAllocator>
standard_alloc_policy(standard_alloc_policy< U > const &)
Type converting constructor.
Definition: allocator.hpp:345
void construct(pointer p, Args &&... args)
Create an object at a specific address.
Definition: allocator.hpp:107
Custom transaction error class.
Definition: pexceptions.hpp:140
allocator()=default
Defaulted constructor.
Persistent memory namespace.
Definition: allocation_flag.hpp:15
persistent_ptr const void specialization.
Definition: persistent_ptr.hpp:88
Custom out of memory error class.
Definition: pexceptions.hpp:120
Commonly used functionality.
(EXPERIMENTAL) Encapsulates the information about the persistent memory allocation model using PMDK's...
Definition: allocator.hpp:432
allocator(allocator< U > const &)
Type converting constructor.
Definition: allocator.hpp:479
~object_traits()=default
Defaulted destructor.
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:406
Resides on pmem class.
Definition: p.hpp:35
Rebind to a different type.
Definition: allocator.hpp:199
object_traits(object_traits< U > const &)
Type converting constructor.
Definition: allocator.hpp:65
object_traits()=default
Defaulted constructor.
void destroy(pointer p)
Destroy an object based on a pointer.
Definition: allocator.hpp:126
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:522
~standard_alloc_policy()=default
Defaulted destructor.
standard_alloc_policy(standard_alloc_policy const &)
Explicit copy constructor.
Definition: allocator.hpp:337
~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:275
Encapsulates object specific allocator functionality.
Definition: allocator.hpp:30
Rebind to a different type.
Definition: allocator.hpp:45
Persistent pointer class.
Definition: persistent_ptr.hpp:183
allocator(allocator< U, P, T2 > const &rhs)
Type converting constructor.
Definition: allocator.hpp:487
standard_alloc_policy(standard_alloc_policy< U > const &)
Type converting constructor.
Definition: allocator.hpp:226
object_traits()=default
Defaulted constructor.
~object_traits()=default
Defaulted destructor.
Convenience extensions for the resides on pmem property template.
The allocation policy template for a given type.
Definition: allocator.hpp:184
Functions for destroying arrays.
Custom transaction error class.
Definition: pexceptions.hpp:158
object_traits(object_traits< U > const &)
Type converting constructor.
Definition: allocator.hpp:172
pointer allocate(size_type cnt, const_pointer=0)
Allocate storage for cnt bytes.
Definition: allocator.hpp:357
Rebind to a different type.
Definition: allocator.hpp:452
~allocator()=default
Defaulted destructor.
void construct(pointer p, const_reference t)
Create an object at a specific address.
Definition: allocator.hpp:82
size_type max_size() const
The largest value that can meaningfully be passed to allocate().
Definition: allocator.hpp:393
Persistent smart pointer.
standard_alloc_policy()=default
Defaulted constructor.
allocator(allocator const &rhs)
Copy constructor.
Definition: allocator.hpp:471
Custom transaction error class.
Definition: pexceptions.hpp:101
pointer allocate(size_type cnt, const_void_pointer=0)
Allocate storage for cnt objects of type T.
Definition: allocator.hpp:242
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:375
size_type max_size() const
The largest value that can meaningfully be passed to allocate().
Definition: allocator.hpp:293
standard_alloc_policy(standard_alloc_policy const &)
Explicit copy constructor.
Definition: allocator.hpp:216