mirror of
https://github.com/boostorg/interprocess.git
synced 2026-01-19 04:12:13 +00:00
Modified examples so that they can be run in parallel.
[SVN r52391]
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <boost/interprocess/allocators/allocator.hpp>
|
||||
#include <boost/interprocess/containers/list.hpp>
|
||||
#include <cstring>
|
||||
#include <boost/aligned_storage.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -20,12 +21,13 @@ int main()
|
||||
|
||||
//Create the static memory who will store all objects
|
||||
const int memsize = 65536;
|
||||
static char static_buffer [memsize];
|
||||
|
||||
static boost::aligned_storage<memsize>::type static_buffer;
|
||||
|
||||
//This managed memory will construct objects associated with
|
||||
//a wide string in the static buffer
|
||||
wmanaged_external_buffer objects_in_static_memory
|
||||
(create_only, static_buffer, memsize);
|
||||
(create_only, &static_buffer, memsize);
|
||||
|
||||
//We optimize resources to create 100 named objects in the static buffer
|
||||
objects_in_static_memory.reserve_named_objects(100);
|
||||
@@ -50,12 +52,12 @@ int main()
|
||||
//pointers and all the pointers constructed int the static memory point
|
||||
//to objects in the same segment, we can create another static buffer
|
||||
//from the first one and duplicate all the data.
|
||||
static char static_buffer2 [memsize];
|
||||
std::memcpy(static_buffer2, static_buffer, memsize);
|
||||
static boost::aligned_storage<memsize>::type static_buffer2;
|
||||
std::memcpy(&static_buffer2, &static_buffer, memsize);
|
||||
|
||||
//Now open the duplicated managed memory passing the memory as argument
|
||||
wmanaged_external_buffer objects_in_static_memory2
|
||||
(open_only, static_buffer2, memsize);
|
||||
(open_only, &static_buffer2, memsize);
|
||||
|
||||
//Check that "MyList" has been duplicated in the second buffer
|
||||
if(!objects_in_static_memory2.find<MyBufferList>(L"MyList").first)
|
||||
|
||||
Reference in New Issue
Block a user