我正在尝试共享一个无序映射(哈希映射),但它在尝试在映射中插入数据的行处出现浮点异常。
有人可以帮助了解我哪里出错了吗?
#include <iostream>
#include <string>
#include <unordered_map>
#include <sys/ipc.h>
#include <sys/shm.h>
int main ()
{
std::unordered_map<std::string,double> *tmp;
key_t key = 5678;
int shmid = shmget(key, 1000, IPC_CREAT | IPC_EXCL | 644);
if(shmid == -1){
std::cerr << "Failed to create the shared segment." << std::endl;
exit(-1);
}
void *addr = shmat(shmid, NULL, 0);
if(addr == (void*)-1){
std::cerr << "Failed to attach the segment to the process." << std::endl;
exit(-1);
}
tmp = static_cast< std::unordered_map<std::string,double>* >(addr);
tmp->insert (std::pair<std::string,double>("abc",1.2));
shmdt(addr);
return 0;
}
谢谢。