2012-04-07 139 views
2

我尝试做以下事情:升压共享存储型

创建一个“大”阵列(1个000 000 +对象)与升压::进程间图书馆

我的代码包含了共享内存以下:

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

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

我的问题是:我如何找出这个升压函数的返回类型是什么?

如果我在上面用以下方法做同样的事情:SingleField而不是“::对它似乎不工作,但我不需要第二个容器,我只需要一个,但一个它不工作!

eclipse的输出对我来说太神秘了,由于我使用boost,因为这些问题我已经停止了好几次了,有没有一种简单的方法来找出函数将返回的“Type”? (我来自Java的所以我已经习惯了有一些‘简单’的定义,说对象X)其实,我会很高兴,如果我能找出哪些特定的函数返回时,与我写我自己的所有功能,这是类型简单但有了这个库我似乎有问题。

第二个问题:为什么这些例子总是以“型”对,它是一个图书馆预条件?

- >我一直在使用的#include尝试,Eclipse的告诉我它的std ::对的问题是,为什么是T *?这是起始段地址吗?

感谢您的时间&答案。

Eclipse的输出:

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 

我看过Boost库手册几次,也许我期待在错误的网站或网页,如果您提供的我想念的信息我会非常高兴。

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

+0

我没有使用升压。之前的Interprocess,但如果你需要在C++中获得函数的返回类型,你总是可以使用'decltype'或'std :: result_of'。在这里看到更多的信息:http://stackoverflow.com/questions/2689709/difference-between-stdresult-of-and-decltype。 – 2012-04-07 20:17:38

+0

所以这基本上是在新的c + +标准中使用的,我曾尝试使用关键字“自动”,我猜我的版本不符合新的C++标准,我会给它一个decltype – 2012-04-07 20:46:24

+1

你可能不得不指定编译器使用最新标准的附加编译标志。对于g ++ - 4.6,你可以在g ++ - 4.7中使用'-std = C++ 0x',以及'-std = C++ 11'。 – 2012-04-08 01:15:33

回答

0

从我的角度来看,也有你的代码有两个主要问题:

  • 你似乎分配TestType类型的4500个对象这可能不是你想要的(除非TestType只需要每个实例一个字节):

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

  • 根据文档(*),则必须提供为构造函数调用括号(您使用的是第二版): TestType * test = testarray.construct<TestType>("TestArray")[45000000]();

    我认为TestType有一个无参数的构造函数。

(*)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

+0

感谢您的回答,主要错误是45 000 000,我认为它是字节,但它实际上是“对象” – 2012-05-15 05:09:16