大共享内存的使用报错
申请了200M共享内存,
win7x64, vc2005
char* addr;
int len=1024*1024*200;
HANDLE handleshm=CreateFileMapping((HANDLE)0xffffffff,NULL,
PAGE_READWRITE,0,len,"MYSHMFILE");
if(GetLastError()==ERROR_ALREADY_EXISTS) createf=0;
if(mode == 1)
{
addr = (char *)MapViewOfFile(handleshm,FILE_MAP_ALL_ACCESS,0,0,0);
}
if(createf) memset(addr,0,len);
然后使用addr,在IDE里查看addr,
addr+1024*1024*9 显示有正确的地址,值为0,看起来没啥问题
addr+1024*1024*10 开始显示为<Bad Ptr>,就开始有问题了
使用后面这内存的结构指针也开始运行错误
First-chance exception at 0x0041fd25 in aa.exe: 0xC0000005: Access violation writing location 0x08f24c24.
First-chance exception at 0x77a74671 in aa.exe: 0xC015000F: The activation context being deactivated is not the most recently activated one.
Unhandled exception at 0x77a74671 in aa.exe: 0xC015000F: The activation context being deactivated is not the most recently activated one.
有什么需要注意的吗?