gpt4 book ai didi

C++ boost : windows shared memory get_size() returns zero

转载 作者:搜寻专家 更新时间:2023-10-31 01:21:54 24 4
gpt4 key购买 nike

以下内容来自官方 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;
}

最佳答案

我想我得到了答案:来自 boost 文档:

Native windows shared memory has also another limitation: a process can open and map the whole shared memory created by another process but it can't know which is the size of that memory. This limitation is imposed by the Windows API so the user must somehow transmit the size of the segment to processes opening the segment.

关于C++ boost : windows shared memory get_size() returns zero,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3365651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com