简体   繁体   中英

Boost Shared Memory Type

I try to do the following thing:

Create a "Big" Array ( 1 000 000 + Objects) into Shared memory with the boost::interprocess library

My Code contains the following:

managed_shared_memory testarray(create_only, "Test", 45000000);

typedef std::pair<SingleField, uint32_t> TestType;
TestType * test = testarray.construct<TestType>("TestArray")[45000000];

My question is: How do I figure out what the return type of this boost function is?

If i do the same above with the following: SingleField instead of "::pair it doesn't seems to work, but i dont need a second container, i only need one but with one it doesn't work!

The output of eclipse is somehow too cryptic for me. Since I work with boost I have been stopped several times because of such issues, is there an easy way to figure out what "Type" the function will give back? (I come from Java so I' am used to have some "Simple" definition which says Object x ) i would actually be happy if I could figure out the type which a specific function returns, with all the functions I write for myself this is simple but with this library I seem to have issues.

Second question: Why are those examples always with "type" pair, is it a library pre-condition?

-> I have tried using #include, Eclipse tells me its std::pair The question is why is it T*? Is this the starting segment address?

Thanks for your time & answers.

Eclipse output:

Multiple markers at this line
- unused variable test
- cannot convert const 
 boost::interprocess::detail::named_proxy<boost::interprocess::segment_manager<char, 
 boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, 
 boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index>, Field, false> to 
 SharedMemoryInitializer::Create()::TestType* in initialization

I have read the boost Library manuals for several times, maybe i look at the wrong sites or pages and i would be pleased if you supply information which i miss.

http://www.boost.org/doc/libs/1_42_0/doc/html/interprocess/quick_guide.html#interprocess.quick_guide.qg_interprocess_container

From my point of view, there are two major issues with your code:

  • you seem to be allocating 45000000 objects of type TestType which is probably not what you want (unless TestType only needs one byte per instance):

    TestType * test = testarray.construct<TestType>("TestArray")[45000000];

  • according to the documentation (*) you must provide provide parentheses for the constructor call (you are using the second version): TestType * test = testarray.construct<TestType>("TestArray")[45000000] () ;

    I assume that TestType has a parameter-less constructor.

(*) http://www.boost.org/doc/libs/1_46_1/doc/html/interprocess/managed_memory_segments.html#interprocess.managed_memory_segments.managed_memory_segment_features.allocation_types

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM