- 论坛徽章:
- 0
|
fd_map=open(path, O_CREAT|O_RDWR|O_TRUNC, 00777);
write(fd_map," ", sizeof(CPipegData));
pmap = (CPipeData*) mmap( NULL,sizeof(CPipeMsgData), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
|
pMsg->dwPduLenth = pmap->Msgdata.msgLenth;
if(pmap->Msgdata.pMsgData && pMsg->dwPduLenth != 0)
{
pMsg->pMsgBuf = new unsigned char[pMsg->dwPduLenth + 1];
memcpy(pMsg->pMsgBuf, pmap->Msgdata.pMsgData, pMsg->dwPduLenth);
pMsg->pMsgBuf[pMsg->dwPduLenth] = '\0';
}
|
我的问题:
1、为什么要加上write(p_msg_map," ", sizeof(CPipeMsgData));进程才能对内存进行写操作?
2、还有我的代码把数据用memcpy到一个对象的成员中,然后把pMsg 的指针的指针保存到msgTempList中,这样push_back多个后,一次性把msgTempList中的数据全部取得,到另外一个跟msgTempList同样类型的list中,在对单个数据操作,把pmsgBuf
指向一个unsigned char* 指针,就出现段错误,但是我确定memcpy(pMsg->pMsgBuf, pmap->Msgdata.pMsgData, pMsg->dwPduLenth);中的pmap->Msgdata.pMsgData 是有数据的啊, 请各位帮我看看!谢谢 |
|