summaryrefslogtreecommitdiff
path: root/libs/interprocess/example/doc_managed_allocation_command.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2015-04-08 03:09:47 +0000
committer <>2015-05-05 14:37:32 +0000
commitf2541bb90af059680aa7036f315f052175999355 (patch)
treea5b214744b256f07e1dc2bd7273035a7808c659f /libs/interprocess/example/doc_managed_allocation_command.cpp
parented232fdd34968697a68783b3195b1da4226915b5 (diff)
downloadboost-tarball-master.tar.gz
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_58_0.tar.bz2.HEADboost_1_58_0master
Diffstat (limited to 'libs/interprocess/example/doc_managed_allocation_command.cpp')
-rw-r--r--libs/interprocess/example/doc_managed_allocation_command.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/libs/interprocess/example/doc_managed_allocation_command.cpp b/libs/interprocess/example/doc_managed_allocation_command.cpp
index 06da74869..61293eb31 100644
--- a/libs/interprocess/example/doc_managed_allocation_command.cpp
+++ b/libs/interprocess/example/doc_managed_allocation_command.cpp
@@ -51,51 +51,53 @@ int main()
//->
//Allocate at least 100 bytes, 1000 bytes if possible
- managed_shared_memory::size_type min_size = 100, preferred_size = 1000;
- managed_shared_memory::size_type received_size;
+ managed_shared_memory::size_type min_size = 100;
+ managed_shared_memory::size_type first_received_size = 1000;
+ std::size_t *hint = 0;
std::size_t *ptr = managed_shm.allocation_command<std::size_t>
- (boost::interprocess::allocate_new, min_size, preferred_size, received_size).first;
+ (boost::interprocess::allocate_new, min_size, first_received_size, hint);
//Received size must be bigger than min_size
- assert(received_size >= min_size);
+ assert(first_received_size >= min_size);
//Get free memory
managed_shared_memory::size_type free_memory_after_allocation = managed_shm.get_free_memory();
//Now write the data
- for(std::size_t i = 0; i < received_size; ++i) ptr[i] = i;
+ for(std::size_t i = 0; i < first_received_size; ++i) ptr[i] = i;
//Now try to triplicate the buffer. We won't admit an expansion
//lower to the double of the original buffer.
//This "should" be successful since no other class is allocating
//memory from the segment
- managed_shared_memory::size_type expanded_size;
- std::pair<std::size_t *, bool> ret = managed_shm.allocation_command
- (boost::interprocess::expand_fwd, received_size*2, received_size*3, expanded_size, ptr);
+ min_size = first_received_size*2;
+ managed_shared_memory::size_type expanded_size = first_received_size*3;
+ std::size_t * ret = managed_shm.allocation_command
+ (boost::interprocess::expand_fwd, min_size, expanded_size, ptr);
//Check invariants
- assert(ret.second == true);
- assert(ret.first == ptr);
- assert(expanded_size >= received_size*2);
+ assert(ptr != 0);
+ assert(ret == ptr);
+ assert(expanded_size >= first_received_size*2);
//Get free memory and compare
managed_shared_memory::size_type free_memory_after_expansion = managed_shm.get_free_memory();
assert(free_memory_after_expansion < free_memory_after_allocation);
//Write new values
- for(std::size_t i = received_size; i < expanded_size; ++i) ptr[i] = i;
+ for(std::size_t i = first_received_size; i < expanded_size; ++i) ptr[i] = i;
//Try to shrink approximately to min_size, but the new size
//should be smaller than min_size*2.
//This "should" be successful since no other class is allocating
//memory from the segment
- managed_shared_memory::size_type shrunk_size;
+ managed_shared_memory::size_type shrunk_size = min_size;
ret = managed_shm.allocation_command
- (boost::interprocess::shrink_in_place, min_size*2, min_size, shrunk_size, ptr);
+ (boost::interprocess::shrink_in_place, min_size*2, shrunk_size, ptr);
//Check invariants
- assert(ret.second == true);
- assert(ret.first == ptr);
+ assert(ptr != 0);
+ assert(ret == ptr);
assert(shrunk_size <= min_size*2);
assert(shrunk_size >= min_size);