I am trying to split an unordered map (hash map), but it ends up with a floating point exception in the row where it is trying to insert data into the map.
Did anyone help to understand what I'm wrong?
#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; }
Thanks.
source share