Skip to content

Commit aab8703

Browse files
committed
Modify experimental "allocate_many" function to take an alignment parameter.
1 parent 5069b61 commit aab8703

File tree

8 files changed

+110
-97
lines changed

8 files changed

+110
-97
lines changed

doc/interprocess.qbk

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3986,7 +3986,7 @@ Here is a small example showing how aligned allocation is used:
39863986

39873987
[section:managed_memory_segment_multiple_allocations Multiple allocation functions]
39883988

3989-
[caution This feature is experimental, interface and ABI are unstable]
3989+
[caution This feature is experimental, API and ABI are unstable]
39903990

39913991
If an application needs to allocate a lot of memory buffers but it needs
39923992
to deallocate them independently, the application is normally forced to loop
@@ -6875,6 +6875,12 @@ thank them:
68756875
* Added `BOOST_HEADER_DEPRECATED` to `<boost/interprocess/containers/*.hpp> headers. They were deprecated several releases ago, but this
68766876
message will annoy existing users to switch to Boost.Container headers.
68776877

6878+
* Changed the interface of [link managed_memory_segment_advanced_features.managed_memory_segment_multiple_allocations Multiple allocation functions]
6879+
(still experimental and API/ABI unstable) to support alignment.
6880+
6881+
Added `BOOST_HEADER_DEPRECATED` to `<boost/interprocess/containers/*.hpp> headers. They were deprecated several releases ago, but this
6882+
message will annoy existing users to switch to Boost.Container headers.
6883+
68786884
* Fixed bugs:
68796885
* [@https://github.com/boostorg/interprocess/issues/242 GitHub #242 (['"Cygwin compatibility issues"])].
68806886
* [@https://github.com/boostorg/interprocess/issues/247 GitHub #247 (['"destruction of move-constructed map using private_adaptive_pool triggers Assertion"])].

example/doc_managed_multiple_allocation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ int main()
3838

3939
managed_shared_memory managed_shm(create_only,test::get_process_id_name(), 65536);
4040

41-
//Allocate 16 elements of 100 bytes in a single call. Non-throwing version.
41+
//Allocate 16 elements of 100 bytes with a minimal alignment of 4, in a single call. Non-throwing version.
4242
multiallocation_chain chain;
43-
managed_shm.allocate_many(std::nothrow, 100, 16, chain);
43+
managed_shm.allocate_many(std::nothrow, 100, 16, 4u, chain);
4444

4545
//Check if the memory allocation was successful
4646
if(chain.empty()) return 1;
@@ -68,7 +68,7 @@ int main()
6868
for(std::size_t i = 0; i < 10; ++i)
6969
sizes[i] = i*3;
7070

71-
managed_shm.allocate_many(sizes, 10, 1, chain);
71+
managed_shm.allocate_many(sizes, 10, 1, 4, chain);
7272
managed_shm.deallocate_many(chain);
7373
return 0;
7474
}

include/boost/interprocess/detail/managed_memory_impl.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,24 +307,24 @@ class basic_managed_memory_impl
307307

308308
//!Allocates n_elements of elem_bytes bytes.
309309
//!Throws bad_alloc on failure. chain.size() is not increased on failure.
310-
void allocate_many(size_type elem_bytes, size_type n_elements, multiallocation_chain &chain)
311-
{ mp_header->allocate_many(elem_bytes, n_elements, chain); }
310+
void allocate_many(size_type elem_bytes, size_type n_elements, size_type alignment, multiallocation_chain &chain)
311+
{ mp_header->allocate_many(elem_bytes, n_elements, alignment, chain); }
312312

313313
//!Allocates n_elements, each one of element_lengths[i]*sizeof_element bytes.
314314
//!Throws bad_alloc on failure. chain.size() is not increased on failure.
315-
void allocate_many(const size_type *element_lengths, size_type n_elements, size_type sizeof_element, multiallocation_chain &chain)
316-
{ mp_header->allocate_many(element_lengths, n_elements, sizeof_element, chain); }
315+
void allocate_many(const size_type *element_lengths, size_type n_elements, size_type sizeof_element, size_type alignment, multiallocation_chain &chain)
316+
{ mp_header->allocate_many(element_lengths, n_elements, sizeof_element, alignment, chain); }
317317

318318
//!Allocates n_elements of elem_bytes bytes.
319319
//!Non-throwing version. chain.size() is not increased on failure.
320-
void allocate_many(const std::nothrow_t &tag, size_type elem_bytes, size_type n_elements, multiallocation_chain &chain)
321-
{ mp_header->allocate_many(tag, elem_bytes, n_elements, chain); }
320+
void allocate_many(const std::nothrow_t &tag, size_type elem_bytes, size_type n_elements, size_type alignment, multiallocation_chain &chain)
321+
{ mp_header->allocate_many(tag, elem_bytes, n_elements, alignment, chain); }
322322

323323
//!Allocates n_elements, each one of
324324
//!element_lengths[i]*sizeof_element bytes.
325325
//!Non-throwing version. chain.size() is not increased on failure.
326-
void allocate_many(const std::nothrow_t &tag, const size_type *elem_sizes, size_type n_elements, size_type sizeof_element, multiallocation_chain &chain)
327-
{ mp_header->allocate_many(tag, elem_sizes, n_elements, sizeof_element, chain); }
326+
void allocate_many(const std::nothrow_t &tag, const size_type *elem_sizes, size_type n_elements, size_type sizeof_element, size_type alignment, multiallocation_chain &chain)
327+
{ mp_header->allocate_many(tag, elem_sizes, n_elements, sizeof_element, alignment, chain); }
328328

329329
//!Deallocates all elements contained in chain.
330330
//!Never throws.

include/boost/interprocess/mem_algo/detail/mem_algo_common.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ class memory_algorithm_common
125125
{ return get_rounded_size(size, Alignment); }
126126

127127
static void allocate_many
128-
(MemoryAlgorithm *memory_algo, size_type elem_bytes, size_type n_elements, multiallocation_chain &chain)
128+
(MemoryAlgorithm *memory_algo, size_type elem_bytes, size_type n_elements, size_type alignment, multiallocation_chain &chain)
129129
{
130-
return this_type::priv_allocate_many(memory_algo, &elem_bytes, n_elements, 0, chain);
130+
return this_type::priv_allocate_many(memory_algo, &elem_bytes, n_elements, alignment, 0, chain);
131131
}
132132

133133
static void deallocate_many(MemoryAlgorithm *memory_algo, multiallocation_chain &chain)
@@ -235,9 +235,10 @@ class memory_algorithm_common
235235
, const size_type *elem_sizes
236236
, size_type n_elements
237237
, size_type sizeof_element
238+
, size_type alignment
238239
, multiallocation_chain &chain)
239240
{
240-
this_type::priv_allocate_many(memory_algo, elem_sizes, n_elements, sizeof_element, chain);
241+
this_type::priv_allocate_many(memory_algo, elem_sizes, n_elements, sizeof_element, alignment, chain);
241242
}
242243

243244
static void* allocate_aligned(MemoryAlgorithm * const memory_algo, const size_type nbytes, const size_type alignment)
@@ -487,6 +488,7 @@ class memory_algorithm_common
487488
( MemoryAlgorithm *memory_algo
488489
, const size_type *elem_sizes
489490
, size_type n_elements
491+
, size_type alignment
490492
, size_type sizeof_element
491493
, multiallocation_chain &chain)
492494
{
@@ -530,7 +532,7 @@ class memory_algorithm_common
530532
size_type received_size = total_bytes;
531533
void *ignore_reuse = 0;
532534
void *ret = memory_algo->priv_allocate
533-
(boost::interprocess::allocate_new, min_allocation, received_size, ignore_reuse);
535+
(boost::interprocess::allocate_new, min_allocation, received_size, ignore_reuse, 1, alignment);
534536
if(!ret){
535537
break;
536538
}

include/boost/interprocess/mem_algo/detail/simple_seq_fit_impl.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,22 @@ class simple_seq_fit_impl
157157

158158
//!Multiple element allocation, same size
159159
//!Experimental. Dont' use
160-
void allocate_many(size_type elem_bytes, size_type num_elements, multiallocation_chain &chain)
160+
void allocate_many(size_type elem_bytes, size_type num_elements, size_type alignment, multiallocation_chain &chain)
161161
{
162162
//-----------------------
163163
boost::interprocess::scoped_lock<interprocess_mutex> guard(m_header);
164164
//-----------------------
165-
algo_impl_t::allocate_many(this, elem_bytes, num_elements, chain);
165+
algo_impl_t::allocate_many(this, elem_bytes, num_elements, alignment, chain);
166166
}
167167

168168
//!Multiple element allocation, different size
169169
//!Experimental. Dont' use
170-
void allocate_many(const size_type *elem_sizes, size_type n_elements, size_type sizeof_element, multiallocation_chain &chain)
170+
void allocate_many(const size_type *elem_sizes, size_type n_elements, size_type sizeof_element, size_type alignment, multiallocation_chain &chain)
171171
{
172172
//-----------------------
173173
boost::interprocess::scoped_lock<interprocess_mutex> guard(m_header);
174174
//-----------------------
175-
algo_impl_t::allocate_many(this, elem_sizes, n_elements, sizeof_element, chain);
175+
algo_impl_t::allocate_many(this, elem_sizes, n_elements, sizeof_element, alignment, chain);
176176
}
177177

178178
//!Multiple element deallocation
@@ -229,7 +229,7 @@ class simple_seq_fit_impl
229229
//!Real allocation algorithm with min allocation option
230230
void * priv_allocate(boost::interprocess::allocation_type command
231231
,size_type min_size
232-
,size_type &prefer_in_recvd_out_size, void *&reuse_ptr, size_type alignof_object = Alignment);
232+
,size_type &prefer_in_recvd_out_size, void *&reuse_ptr, size_type sizeof_object = 1, size_type alignof_object = Alignment);
233233

234234
//!Returns the number of total units that a user buffer
235235
//!of "userbytes" bytes really occupies (including header)
@@ -635,7 +635,7 @@ simple_seq_fit_impl<MutexFamily, VoidPointer>::
635635
template<class MutexFamily, class VoidPointer>
636636
void * simple_seq_fit_impl<MutexFamily, VoidPointer>::
637637
priv_allocate(boost::interprocess::allocation_type command
638-
,size_type limit_size, size_type &prefer_in_recvd_out_size, void *&reuse_ptr, size_type alignof_object)
638+
,size_type limit_size, size_type &prefer_in_recvd_out_size, void *&reuse_ptr, size_type /*sizeof_object*/, size_type alignof_object)
639639
{
640640
//Backwards expansion not supported
641641
command &= ~boost::interprocess::expand_bwd;

include/boost/interprocess/mem_algo/rbtree_best_fit.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,22 @@ class rbtree_best_fit
204204

205205
//!Multiple element allocation, same size
206206
//!Experimental. Dont' use
207-
void allocate_many(size_type elem_bytes, size_type num_elements, multiallocation_chain &chain)
207+
void allocate_many(size_type elem_bytes, size_type num_elements, size_type alignment, multiallocation_chain &chain)
208208
{
209209
//-----------------------
210210
boost::interprocess::scoped_lock<mutex_type> guard(m_header);
211211
//-----------------------
212-
algo_impl_t::allocate_many(this, elem_bytes, num_elements, chain);
212+
algo_impl_t::allocate_many(this, elem_bytes, num_elements, alignment, chain);
213213
}
214214

215215
//!Multiple element allocation, different size
216216
//!Experimental. Dont' use
217-
void allocate_many(const size_type *elem_sizes, size_type n_elements, size_type sizeof_element, multiallocation_chain &chain)
217+
void allocate_many(const size_type *elem_sizes, size_type n_elements, size_type sizeof_element, size_type alignment, multiallocation_chain &chain)
218218
{
219219
//-----------------------
220220
boost::interprocess::scoped_lock<mutex_type> guard(m_header);
221221
//-----------------------
222-
algo_impl_t::allocate_many(this, elem_sizes, n_elements, sizeof_element, chain);
222+
algo_impl_t::allocate_many(this, elem_sizes, n_elements, sizeof_element, alignment, chain);
223223
}
224224

225225
//!Multiple element allocation, different size

include/boost/interprocess/segment_manager.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ class segment_manager_base
210210
//Experimental. Don't use.
211211
//!Allocates n_elements of elem_bytes bytes.
212212
//!Throws bad_alloc on failure. chain.size() is not increased on failure.
213-
void allocate_many(size_type elem_bytes, size_type n_elements, multiallocation_chain &chain)
213+
void allocate_many(size_type elem_bytes, size_type n_elements, size_type alignment, multiallocation_chain &chain)
214214
{
215215
size_type prev_size = chain.size();
216-
MemoryAlgorithm::allocate_many(elem_bytes, n_elements, chain);
216+
MemoryAlgorithm::allocate_many(elem_bytes, n_elements, alignment, chain);
217217
if(!elem_bytes || chain.size() == prev_size){
218218
throw bad_alloc();
219219
}
@@ -222,10 +222,10 @@ class segment_manager_base
222222
//Experimental. Don't use.
223223
//!Allocates n_elements, each one of element_lengths[i]*sizeof_element bytes.
224224
//!Throws bad_alloc on failure. chain.size() is not increased on failure.
225-
void allocate_many(const size_type *element_lengths, size_type n_elements, size_type sizeof_element, multiallocation_chain &chain)
225+
void allocate_many(const size_type *element_lengths, size_type n_elements, size_type sizeof_element, size_type alignment, multiallocation_chain &chain)
226226
{
227227
size_type prev_size = chain.size();
228-
MemoryAlgorithm::allocate_many(element_lengths, n_elements, sizeof_element, chain);
228+
MemoryAlgorithm::allocate_many(element_lengths, n_elements, sizeof_element, alignment, chain);
229229
if(!sizeof_element || chain.size() == prev_size){
230230
throw bad_alloc();
231231
}
@@ -234,15 +234,15 @@ class segment_manager_base
234234
//Experimental. Don't use.
235235
//!Allocates n_elements of elem_bytes bytes.
236236
//!Non-throwing version. chain.size() is not increased on failure.
237-
void allocate_many(const std::nothrow_t &, size_type elem_bytes, size_type n_elements, multiallocation_chain &chain)
238-
{ MemoryAlgorithm::allocate_many(elem_bytes, n_elements, chain); }
237+
void allocate_many(const std::nothrow_t &, size_type elem_bytes, size_type n_elements, size_type alignment, multiallocation_chain &chain)
238+
{ MemoryAlgorithm::allocate_many(elem_bytes, n_elements, alignment, chain); }
239239

240240
//Experimental. Don't use.
241241
//!Allocates n_elements, each one of
242242
//!element_lengths[i]*sizeof_element bytes.
243243
//!Non-throwing version. chain.size() is not increased on failure.
244-
void allocate_many(const std::nothrow_t &, const size_type *elem_sizes, size_type n_elements, size_type sizeof_element, multiallocation_chain &chain)
245-
{ MemoryAlgorithm::allocate_many(elem_sizes, n_elements, sizeof_element, chain); }
244+
void allocate_many(const std::nothrow_t &, const size_type *elem_sizes, size_type n_elements, size_type sizeof_element, size_type alignment, multiallocation_chain &chain)
245+
{ MemoryAlgorithm::allocate_many(elem_sizes, n_elements, sizeof_element, alignment, chain); }
246246

247247
//Experimental. Don't use.
248248
//!Deallocates all elements contained in chain.

0 commit comments

Comments
 (0)