summaryrefslogtreecommitdiff
path: root/libs/interprocess/example
diff options
context:
space:
mode:
Diffstat (limited to 'libs/interprocess/example')
-rw-r--r--libs/interprocess/example/doc_managed_allocation_command.cpp34
-rw-r--r--libs/interprocess/example/doc_managed_mapped_file.cpp9
-rw-r--r--libs/interprocess/example/doc_managed_multiple_allocation.cpp9
3 files changed, 36 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);
diff --git a/libs/interprocess/example/doc_managed_mapped_file.cpp b/libs/interprocess/example/doc_managed_mapped_file.cpp
index 723fb3aba..2b59626f4 100644
--- a/libs/interprocess/example/doc_managed_mapped_file.cpp
+++ b/libs/interprocess/example/doc_managed_mapped_file.cpp
@@ -7,6 +7,8 @@
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
+#if defined(BOOST_INTERPROCESS_MAPPED_FILES)
+
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>
@@ -106,3 +108,10 @@ int main ()
}
#include <boost/interprocess/detail/config_end.hpp>
+
+#else //#if defined(BOOST_INTERPROCESS_MAPPED_FILES)
+int main()
+{
+ return 0;
+}
+#endif//#if defined(BOOST_INTERPROCESS_MAPPED_FILES)
diff --git a/libs/interprocess/example/doc_managed_multiple_allocation.cpp b/libs/interprocess/example/doc_managed_multiple_allocation.cpp
index 1a7589d6f..97835c56a 100644
--- a/libs/interprocess/example/doc_managed_multiple_allocation.cpp
+++ b/libs/interprocess/example/doc_managed_multiple_allocation.cpp
@@ -7,6 +7,8 @@
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
+#if defined(BOOST_INTERPROCESS_MAPPED_FILES)
+
#include <boost/interprocess/detail/config_begin.hpp>
//[doc_managed_multiple_allocation
#include <boost/interprocess/managed_shared_memory.hpp>
@@ -89,3 +91,10 @@ int main()
}
//]
#include <boost/interprocess/detail/config_end.hpp>
+
+#else //#if defined(BOOST_INTERPROCESS_MAPPED_FILES)
+int main()
+{
+ return 0;
+}
+#endif//#if defined(BOOST_INTERPROCESS_MAPPED_FILES)