- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 this 创建内存映射文件回答,但我收到编译错误。这是我的代码:
namespace bi = boost::interprocess;
std::string vecFile = "vector.dat";
bi::managed_mapped_file file_vec(bi::open_or_create,vecFile.c_str(), sizeof(struct Rectangle) * data_size);
typedef bi::allocator<struct Rectangle, bi::managed_mapped_file::segment_manager> rect_alloc;
typedef std::vector<struct Rectangle, rect_alloc> MyVec;
MyVec * vecptr = file_vec.find_or_construct<MyVec>("myvector")(file_vec.get_segment_manager());
vecptr->push_back(random_rectangle);
结构是这样的:
struct Rectangle{
Rectangle(float *minArr, float *maxArr, int arr, int exp, int ID){
this->arrival = arr;
this->expiry = exp;
this->id = ID;
for(int i=0; i < 2; i++){
min[i] = minArr[i];
max[i] = maxArr[i];
}
int arrival, expiry, id;
float min[2];
float max[2];
}
我得到的错误是:编译器无法从“boost::interprocess::offset_ptr”推断出“_Ty*”的模板参数。我做错了什么?
最佳答案
我觉得没问题:
#include <boost/interprocess/managed_mapped_file.hpp>
#include <vector>
namespace bi = boost::interprocess;
struct Rectangle {
Rectangle(float *minArr, float *maxArr, int arr, int exp, int ID) {
this->arrival = arr;
this->expiry = exp;
this->id = ID;
for (int i = 0; i < 2; i++) {
min[i] = minArr[i];
max[i] = maxArr[i];
}
};
int arrival, expiry, id;
float min[2];
float max[2];
};
namespace Shared {
using segment = bi::managed_mapped_file;
using mgr = segment::segment_manager;
using alloc = bi::allocator<Rectangle, mgr>;
using vector = std::vector<Rectangle, alloc>;
}
Rectangle random_rectangle() {
float dummy[2] = { };
return { dummy, dummy, 0, 0, 0 };
}
int main() {
#define data_size 10
std::string vecFile = "vector.dat";
Shared::segment mmem(bi::open_or_create, vecFile.c_str(), (10u<<10) + sizeof(struct Rectangle) * data_size);
Shared::vector *vecptr = mmem.find_or_construct<Shared::vector>("myvector")(mmem.get_segment_manager());
vecptr->push_back(random_rectangle());
}
如果它不能完全按照上面的方式编译,请注意您的库和编译器的版本。考虑升级。
关于C++: boost::interprocess 内存映射文件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34822114/
有没有人尝试创建进程间通信的日志文件?有人可以就实现这一目标的最佳方式给我一些建议吗? 最佳答案 这个问题不太清楚,评论使它不太清楚,但无论如何...... 首先要尝试的两件事是 ipcs和 stra
我使用boost::interprocess在共享内存中创建了boost::multi_index数据结构。有许多客户端进程将访问此数据结构。访问时,我将锁定数据结构。我遇到的问题是,一旦客户端进程正
我正在尝试使用 this 创建内存映射文件回答,但我收到编译错误。这是我的代码: namespace bi = boost::interprocess; std::string vecFile = "
我正在编写实时数据以增加共享内存。最初我每次想访问 shm 时都使用它: boost::interprocess::managed_shared_memory segment(boost::inte
我正在查看两个进程共享互斥锁和条件变量的 Boost 示例代码: https://www.boost.org/doc/libs/1_57_0/doc/html/interprocess/synchro
我刚刚读了this page Boost.Interprocess 文档。这似乎表明,为了适应不同操作系统之间的差异并达成某种共识,某些进程间机制并没有使用操作系统提供的直接对应的本地机制来实现,而是
我有以下崩溃的代码。我怀疑这是因为分配了对堆栈的引用,所以我遇到了这个问题。但我想避免每次都必须堆栈分配互斥锁和作用域锁的成本 class Cache { public: void cr
在 Boost.Interprocess 文档中 Where is this being allocated?据称 Boost.Interprocess 容器同时使用两种机制放置在共享内存中: Boo
我已经在这个问题上待了好几天(甚至在 boost 论坛上的 posted)并且能够让第二个进程识别锁定的互斥锁似乎不起作用。请帮忙。这是代码: 通用头文件:SharedObject.hpp #ifnd
我正在使用 boost::interprocess::named_upgradable_mutex 来同步一些进程。 我正在使用 boost::interprocess::sharable_lock
我搜索在两个进程之间共享一个结构。但我没有成功。你能帮忙理解吗? 这是我的第一个过程的代码: #include #include #include #include #include #in
我正在移植源代码以打开/读取/写入在多个进程之间共享的文件。它在 Windows 下运行良好,因为它主要使用 boost::interprocess (1.44),我没想到会有太多问题,但我发现了一些
我想我终于掌握了 boost:interprocess 库的基础知识,并且在处理包含一些全是标准数据类型的成员变量的相对简单的类时,我一直在成功地使用它。 但是,我现在面临着将一个相当复杂的类推送到进
现在查看此链接: http://www.boost.org/doc/libs/1_56_0/doc/html/interprocess/quick_guide.html#interprocess.qu
我想用 boost 编写一个简单的应用程序,将字符串对象传递给其他进程。它编译得很好,但是当我尝试从第二个进程打印出字符串时,以下消息被发送到控制台并且第二个进程崩溃: ../boost_1_44_0
目前,我有 2 个进程使用 message_queue 和 shared_memory 表单 boost 进行通信。一切如常。 现在我需要使这个进程中的一个成为多线程的(再次感谢 boost),我想知
我需要围绕一个硬件进行进程间同步。因为此代码需要在 Windows 和 Linux 上运行,所以我使用 Boost 进程间互斥锁进行封装。一切正常接受我检查互斥量放弃的方法。这有可能发生,所以我必须为
这是一段我用来在共享内存上分配映射的代码,我正在使用boost::interprocess和托管共享内存段,现在的问题是我遇到了内存泄漏。下面给出的是最高输出。 最高输出: PID USER
我有一个应用程序实现了 boost named_mutex 以锁定 C++ 项目 (Visual Studio) 中的多个模块。我需要不惜一切代价删除所有 boost 依赖项。 还有其他方法可以实现吗
我似乎遇到了 boost::interprocess::file_lock 的问题 我的流程 1 本质上是 boost::interprocess::file_lock test_lock("
我是一名优秀的程序员,十分优秀!