提升共享内存类型
Boost Shared Memory Type
我尝试做以下事情:
使用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
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 类型总是使用其大小存储在内存中吗
- 使用Boost Interprocess创建托管共享内存需要很长时间
- 使用模板类的自定义列表类型中的内存泄漏
- 多个"常量引用"变量可以共享同一个内存吗?
- 模板函数如何处理可能共享一个交集的多个类型名称?
- 使用共享指针时,从共享指针本身释放内存的机制是什么
- 字符串共享内存映射的向量
- 具有 STL 向量类型成员的类的复制内存
- 在这种特殊情况下,我是否需要在共享内存中使用原子类型
- 为什么 vkGetPhysicalDeviceMemoryProperties 返回多个相同的内存类型?
- 为什么 XOCDE STL 源内存类型定义有 |象征
- 有没有办法区分对象实例使用的内存类型
- 希望有效地克服 Boost.Process 间共享内存中映射中键类型之间的不匹配
- 提升共享内存类型
- 指向共享内存POSIX的指针类型
- c++中等效的内存类型是什么?
- Arduino内存类型,学术
- 在内核调用(计算1.1或1.2)期间,仅用于设备计算的CUDA内存(类型)