提升共享内存类型

Boost Shared Memory Type

本文关键字:内存类型 共享      更新时间:2023-10-16

我尝试做以下事情:

使用boost::进程间库在共享内存中创建一个"大"数组(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 而不是"::p air"它似乎不起作用,但我不需要第二个容器,我只需要一个,但有一个它不起作用!

日食的输出对我来说有点太神秘了。由于我使用 boost 工作,由于这些问题,我已经多次停止,有没有一种简单的方法可以弄清楚函数会返回什么"类型"?(我来自Java,所以我习惯于有一些"简单"的定义,说Object x)如果我能弄清楚特定函数返回的类型,我实际上会很高兴,我为自己编写的所有函数都很简单,但是有了这个库,我似乎遇到了问题。

第二个问题:为什么那些例子总是带有"类型"对,是库的前提条件吗?

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

感谢您的时间和答案。

日食输出:

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

我已经多次阅读了提升图书馆手册,也许我看错了网站或页面,如果您提供我错过的信息,我会很高兴。

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

在我看来,您的代码有两个主要问题:

  • 您似乎正在分配 45000000 个类型 TestType 的对象,这可能不是您想要的(除非每个实例只需要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