Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 58b7ce7

Browse files
Merge pull request #1220 from lukaszstolarczuk/extend-allocation-feature-docs
Extend allocation feature docs
2 parents 3cc48e1 + 901eae9 commit 58b7ce7

File tree

9 files changed

+115
-25
lines changed

9 files changed

+115
-25
lines changed

doc/groups_definitions.dox

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,30 @@
159159
* - [blog post about transactional allocations](https://pmem.io/2016/05/19/cpp-06.html)
160160
*/
161161

162-
/** @defgroup allocation Allocation*/
162+
/** @defgroup allocation Allocation
163+
* Functions and classes to support allocations on pmem
164+
*
165+
* Libpmemobj-cpp introduced special functions for allocating objects and arrays
166+
* of objects on persistent memory, with ease. For all `make_persistent` specializations
167+
* there are also `delete_persistent` counterparts. The latter are used to free memory
168+
* of previously allocated objects or arrays, and calling their destructors. Each
169+
* specialization comes in two versions - atomic and transactional. First one is
170+
* distinguished with `_atomic` suffix (e.g. `make_persistent_atomic()`) and should not
171+
* be called within an active transaction - it may lead to undefined behavior in case
172+
* of transaction's rollback. On the other hand, transactional functions will throw
173+
* an exception if called outside of an active transaction.
174+
*
175+
* For more flexibly approach we introduced pmem::obj::allocator class, which implements
176+
* the concept of C++ Allocator. Allocation and deallocation using this class can only
177+
* happen within an active transactions.
178+
*
179+
* The *typical use case* of data allocation on pmem would be:
180+
* @snippet make_persistent/make_persistent.cpp make_example
181+
*
182+
* For allocator usage see pmem::obj::experimental::inline_string example:
183+
* @snippet inline_string/inline_string.cpp inline_string_example
184+
*/
185+
163186
/** @defgroup data_view Data View*/
164187
/** @defgroup synchronization Synchronization Primitives*/
165188
/** @defgroup primitives Primitives*/

include/libpmemobj++/allocator.hpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ class object_traits {
136136
};
137137

138138
/**
139-
* Object traits specialization for the void type. Designed to be used
140-
* with C++ allocators. Can be specialized if necessary.
139+
* Object traits specialization for the void type.
140+
*
141+
* Designed to be used with C++ allocators. Can be specialized if necessary.
141142
* @ingroup allocation
142143
*/
143144
template <>
@@ -179,8 +180,8 @@ class object_traits<void> {
179180
/**
180181
* The allocation policy template for a given type.
181182
*
182-
* Can be specialized for a given type. Designed to be used with C++ allocators.
183-
* Can be specialized if necessary.
183+
* Can be specialized, if necessary, for a given type. Designed to be used
184+
* with C++ allocators.
184185
* @ingroup allocation
185186
*/
186187
template <typename T>
@@ -236,7 +237,8 @@ class standard_alloc_policy {
236237
*
237238
* @param[in] cnt the number of objects to allocate memory for.
238239
*
239-
* @throw transaction_scope_error if called outside of a transaction.
240+
* @throw transaction_scope_error if called outside of an active
241+
* transaction.
240242
* @throw transaction_out_of_memory if there is no free memory of
241243
* requested size.
242244
* @throw transaction_alloc_error on transactional allocation failure.
@@ -273,6 +275,10 @@ class standard_alloc_policy {
273275
* intervening call to deallocate.
274276
*
275277
* @param[in] p pointer to the memory to be deallocated.
278+
*
279+
* @throw transaction_scope_error if called outside of an active
280+
* transaction.
281+
* @throw transaction_free_error on transactional free failure.
276282
*/
277283
void
278284
deallocate(pointer p, size_type = 0)
@@ -355,7 +361,11 @@ class standard_alloc_policy<void> {
355361
*
356362
* @param[in] cnt the number of bytes to be allocated.
357363
*
358-
* @throw transaction_scope_error if called outside of a transaction.
364+
* @throw transaction_scope_error if called outside of an active
365+
* transaction.
366+
* @throw transaction_out_of_memory if there is no free memory of
367+
* requested size.
368+
* @throw transaction_alloc_error on transactional allocation failure.
359369
*/
360370
pointer
361371
allocate(size_type cnt, const_pointer = 0)
@@ -388,6 +398,10 @@ class standard_alloc_policy<void> {
388398
* intervening call to deallocate.
389399
*
390400
* @param[in] p pointer to the memory to be deallocated.
401+
*
402+
* @throw transaction_scope_error if called outside of an active
403+
* transaction.
404+
* @throw transaction_free_error on transactional free failure.
391405
*/
392406
void
393407
deallocate(pointer p, size_type = 0)
@@ -446,6 +460,7 @@ operator==(standard_alloc_policy<T> const &, OtherAllocator const &)
446460
* the knowledge of the pointer type, their difference type, the type of the
447461
* size of objects in this allocation model as well as memory allocation and
448462
* deallocation primitives.
463+
* @ingroup allocation
449464
*/
450465
template <typename T, typename Policy = standard_alloc_policy<T>,
451466
typename Traits = object_traits<T>>

include/libpmemobj++/container/segment_vector.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,8 +2553,8 @@ segment_vector<T, Policy>::construct_range(size_type idx, InputIt first,
25532553
* gap for count elements starting at index idx. If there is not enough
25542554
* space available, reallocation occurs.
25552555
*
2556-
* param[in] idx index number where gap should be made.
2557-
* param[in] count length (expressed in number of elements) of the gap.
2556+
* @param[in] idx index number where gap should be made.
2557+
* @param[in] count length (expressed in number of elements) of the gap.
25582558
*
25592559
* @pre must be called in transaction scope.
25602560
*

include/libpmemobj++/container/vector.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,9 +2269,9 @@ vector<T>::construct_or_assign(size_type idx, InputIt first, InputIt last)
22692269
* reallocation occurs with new recommended size. Range specified by first, last
22702270
* is then inserted into the gap.
22712271
*
2272-
* param[in] idx index number where insert should be made
2273-
* param[in] first iterator to beginning of the range to insert
2274-
* param[in] last iterator to end of the range to insert
2272+
* @param[in] idx index number where insert should be made
2273+
* @param[in] first iterator to beginning of the range to insert
2274+
* @param[in] last iterator to end of the range to insert
22752275
*
22762276
* @pre must be called in transaction scope.
22772277
*
@@ -2355,7 +2355,7 @@ vector<T>::internal_insert(size_type idx, InputIt first, InputIt last)
23552355
* container is reduced to its first capacity_new elements. If was never
23562356
* allocated behaves as an alloc call.
23572357
*
2358-
* param[in] capacity_new new capacity.
2358+
* @param[in] capacity_new new capacity.
23592359
*
23602360
* @pre must be called in transaction scope.
23612361
*

include/libpmemobj++/experimental/inline_string.hpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,48 @@ class basic_inline_string : public basic_inline_string_base<CharT, Traits> {
214214
}
215215
};
216216

217+
/**
218+
* The most typical dram_inline_string usage - the char specialization.
219+
* See basic_dram_inline_string for details.
220+
* @ingroup experimental_containers
221+
*/
217222
using dram_inline_string = basic_dram_inline_string<char>;
223+
/**
224+
* The wide char specialization.
225+
* @ingroup experimental_containers
226+
*/
218227
using dram_inline_wstring = basic_dram_inline_string<wchar_t>;
228+
/**
229+
* The char16 specialization.
230+
* @ingroup experimental_containers
231+
*/
219232
using dram_inline_u16string = basic_dram_inline_string<char16_t>;
233+
/**
234+
* The char32 specialization.
235+
* @ingroup experimental_containers
236+
*/
220237
using dram_inline_u32string = basic_dram_inline_string<char32_t>;
221238

239+
/**
240+
* The most typical inline_string usage - the char specialization.
241+
* See basic_inline_string for details.
242+
* @ingroup experimental_containers
243+
*/
222244
using inline_string = basic_inline_string<char>;
245+
/**
246+
* The wide char specialization.
247+
* @ingroup experimental_containers
248+
*/
223249
using inline_wstring = basic_inline_string<wchar_t>;
250+
/**
251+
* The char16 specialization.
252+
* @ingroup experimental_containers
253+
*/
224254
using inline_u16string = basic_inline_string<char16_t>;
255+
/**
256+
* The char32 specialization.
257+
* @ingroup experimental_containers
258+
*/
225259
using inline_u32string = basic_inline_string<char32_t>;
226260

227261
/**

include/libpmemobj++/make_persistent.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
/**
55
* @file
6-
* Persistent_ptr transactional allocation functions for objects. The typical
7-
* usage examples would be:
6+
* persistent_ptr transactional allocation functions for objects.
7+
*
8+
* The typical usage examples would be:
89
* @snippet make_persistent/make_persistent.cpp make_example
910
*/
1011

@@ -42,6 +43,8 @@ namespace obj
4243
*
4344
* @throw transaction_scope_error if called outside of an active
4445
* transaction
46+
* @throw transaction_out_of_memory if there is no free memory of
47+
* requested size.
4548
* @throw transaction_alloc_error on transactional allocation failure.
4649
* @throw rethrow exception from T constructor
4750
* @ingroup allocation
@@ -84,6 +87,8 @@ make_persistent(allocation_flag flag, Args &&... args)
8487
*
8588
* @throw transaction_scope_error if called outside of an active
8689
* transaction
90+
* @throw transaction_out_of_memory if there is no free memory of
91+
* requested size.
8792
* @throw transaction_alloc_error on transactional allocation failure.
8893
* @throw rethrow exception from T constructor
8994
* @ingroup allocation

include/libpmemobj++/make_persistent_array.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
/**
55
* @file
6-
* Persistent_ptr allocation functions for arrays. The typical usage examples
7-
* would be:
6+
* persistent_ptr transactional allocation functions for arrays.
7+
*
8+
* The typical usage examples would be:
89
* @snippet make_persistent/make_persistent.cpp make_array_example
910
*/
1011

@@ -42,6 +43,8 @@ namespace obj
4243
*
4344
* @throw transaction_scope_error if called outside of an active
4445
* transaction
46+
* @throw transaction_out_of_memory if there is no free memory of
47+
* requested size.
4548
* @throw transaction_alloc_error on transactional allocation failure.
4649
* @throw rethrow exception from T constructor
4750
* @ingroup allocation
@@ -109,6 +112,8 @@ make_persistent(std::size_t N, allocation_flag flag = allocation_flag::none())
109112
*
110113
* @throw transaction_scope_error if called outside of an active
111114
* transaction
115+
* @throw transaction_out_of_memory if there is no free memory of
116+
* requested size.
112117
* @throw transaction_alloc_error on transactional allocation failure.
113118
* @throw rethrow exception from T constructor
114119
* @ingroup allocation
@@ -174,6 +179,7 @@ make_persistent(allocation_flag flag = allocation_flag::none())
174179
* @throw transaction_scope_error if called outside of an active
175180
* transaction
176181
* @throw transaction_free_error on transactional free failure.
182+
* @ingroup allocation
177183
*/
178184
template <typename T>
179185
void
@@ -220,6 +226,7 @@ delete_persistent(typename detail::pp_if_array<T>::type ptr, std::size_t N)
220226
* @throw transaction_scope_error if called outside of an active
221227
* transaction
222228
* @throw transaction_free_error on transactional free failure.
229+
* @ingroup allocation
223230
*/
224231
template <typename T>
225232
void

include/libpmemobj++/make_persistent_array_atomic.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2-
/* Copyright 2016-2020, Intel Corporation */
2+
/* Copyright 2016-2021, Intel Corporation */
33

44
/**
55
* @file
6-
* Atomic persistent_ptr allocation functions for arrays. The typical usage
7-
* examples would be:
6+
* persistent_ptr atomic allocation functions for arrays.
7+
*
8+
* The typical usage examples would be:
89
* @snippet make_persistent/make_persistent.cpp make_array_atomic_example
910
*/
1011

@@ -40,6 +41,7 @@ namespace obj
4041
* @param[in] flag affects behaviour of allocator
4142
*
4243
* @throw std::bad_alloc on allocation failure.
44+
* @ingroup allocation
4345
*/
4446
template <typename T>
4547
void
@@ -72,6 +74,7 @@ make_persistent_atomic(
7274
* @param[in] flag affects behaviour of allocator
7375
*
7476
* @throw std::bad_alloc on allocation failure.
77+
* @ingroup allocation
7578
*/
7679
template <typename T>
7780
void
@@ -98,8 +101,9 @@ make_persistent_atomic(
98101
* cleanup must be performed elsewhere. Do *NOT* use this inside transactions,
99102
* as it might lead to undefined behavior in the presence of transaction aborts.
100103
*
101-
* param[in,out] ptr the persistent_ptr whose pointee is to be
104+
* @param[in,out] ptr the persistent_ptr whose pointee is to be
102105
* deallocated.
106+
* @ingroup allocation
103107
*/
104108
template <typename T>
105109
void
@@ -120,7 +124,8 @@ delete_persistent_atomic(typename detail::pp_if_array<T>::type &ptr,
120124
* cleanup must be performed elsewhere. Do *NOT* use this inside transactions,
121125
* as it might lead to undefined behavior in the presence of transaction aborts.
122126
*
123-
* param[in,out] ptr the persistent_ptr whose pointee is to be deallocated.
127+
* @param[in,out] ptr the persistent_ptr whose pointee is to be deallocated.
128+
* @ingroup allocation
124129
*/
125130
template <typename T>
126131
void

include/libpmemobj++/make_persistent_atomic.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
/**
55
* @file
6-
* Persistent_ptr atomic allocation functions for objects. The typical usage
7-
* examples would be:
6+
* persistent_ptr atomic allocation functions for objects.
7+
*
8+
* The typical usage examples would be:
89
* @snippet make_persistent/make_persistent.cpp make_atomic_example
910
*/
1011

@@ -97,7 +98,7 @@ make_persistent_atomic(pool_base &pool,
9798
* cleanup must be performed elsewhere. Do *NOT* use this inside transactions,
9899
* as it might lead to undefined behavior in the presence of transaction aborts.
99100
*
100-
* param[in,out] ptr the persistent_ptr whose pointee is to be
101+
* @param[in,out] ptr the persistent_ptr whose pointee is to be
101102
* deallocated.
102103
* @ingroup allocation
103104
*/

0 commit comments

Comments
 (0)