【发布时间】:2014-10-24 08:45:56
【问题描述】:
我有一个关注者boost::interprocess::map:
using boost::interprocess;
std::shared_ptr< map<uint32, managed_shared_memory*> > myMap;
我有一个方法()插入到这个地图中:
void InsertInMap(uint32 i)
{
myMap->insert( std::make_pair (i, // runtime error here
new managed_shared_memory(create_only, "Test", 256)) );
}
在main(),我这样称呼它:
int main()
{
InsertInMap(1);
}
这编译得很好。
但是当我运行我的程序时,我在标记的行(插入时)收到以下运行时错误:
memory access violation occurred at address ......, while attempting to read inaccessible data
我错过了什么吗?
【问题讨论】:
-
这与 boost、interprocess 或 maps 无关。初始化变量。而且不要一直
new(这不是Java!) -
好吧,如果您指向上面
InsertInMap()中的new,那么这是必需的,因为我希望为每个传递的i提供一个新内存!就错误而言,我已经意识到我犯的愚蠢错误!
标签: c++ boost boost-interprocess