I'm trying to work with the memory mapped file API in Windows, and am having some pretty serious issues. I'm trying to generate a 16GB file so I started with a little test to see how things would go. Here is the code:
HANDLE file = CreateFile("output.raw", GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE filemap = CreateFileMapping(file, NULL, PAGE_READWRITE, 0x4, 0, NULL); unsigned char* data = (unsigned char*)MapViewOfFile(filemap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
As far as I know I set this up right. This should create a 16GB file and give me a pointer to the full 16GB of data. To make sure it works I output a magic number every 4 million bytes or so, for the entire length of the file, and then I opened it up in a hex editor to make sure it had worked, which it had. Then I tried writing a gigabytes worth of data, again spread out over the entire 16GB. My computer promptly froze and 10 minutes later, unable to move my mouse or get any other kind of feedback, I pulled the plug.
What am I doing wrong?