C++ BOOST:Windows 共享内存 get_size() 返回零
以下内容来自 BOOST 官方文档。 为什么我在调用 region.get_size()
时得到的大小总是为零?我做错了什么?
int main(int argc, char *argv[])
{
//Create a native windows shared memory object.
windows_shared_memory shm (create_only, "MySharedMemory", read_write, 1000);
//Map the whole shared memory in this process
mapped_region region(shm, read_write);
cout << "SIZE IS " << region.get_size() << endl;
return 0;
}
The below is from the official BOOST docs.
Why do I always get size of zero when calling region.get_size()
? What am I doing wrong?
int main(int argc, char *argv[])
{
//Create a native windows shared memory object.
windows_shared_memory shm (create_only, "MySharedMemory", read_write, 1000);
//Map the whole shared memory in this process
mapped_region region(shm, read_write);
cout << "SIZE IS " << region.get_size() << endl;
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我得到了答案:
来自增强文档:
I think I got the answer:
From boost docs:
在 boost::interprocess您正在使用的
mapped_region
构造函数的文档说:因此提供非零大小,一切都会按预期工作:
mapped_region 区域(shm, read_write, 0, 1000);
In the boost::interprocess documentation for the
mapped_region
constructor you're using it says:So provide a non-zero size and everything will work as expected:
mapped_region region(shm, read_write, 0, 1000);