Time:11-06
CodePudding user response:
No problem when the Shared memory size set to 1024, when set to 10 * 1024 in meset error here, why?
1 integer times to deal with according to the system page 2 the returned handle & amp; Buffer pointer to determine whether effective SYSTEM_INFO sysInfo. GetNativeSystemInfo (& amp; The sysInfo); Int BUF_SIZE=102400 * sysInfo. DwPageSize;
Int Test () {Int iErr=0; TCHAR szName []=TEXT (" Global \ \ MyFileMappingObject "); SYSTEM_INFO sysInfo. GetNativeSystemInfo (& amp; The sysInfo); Int BUF_SIZE=102400 * sysInfo. DwPageSize; HANDLE hMapFile=NULL; LPVOID pbufs=NULL; Do {HMapFile=CreateFileMapping (INVALID_HANDLE_VALUE,//use the paging file NULL,//the default security PAGE_READWRITE,//read/write access 0,//Max. Object size BUF_SIZE,//buffer size SzName);//the name of the mapping object If (hMapFile!=NULL) {Printf (" CreateFileMapping % d (bytes) ok \ n ", BUF_SIZE); } The else {IErr=GetLastError (); Printf (" Could not create the file mapping object (% d). \ n ", iErr); break; } Pbufs=MapViewOfFile (hMapFile,//handle to the map object FILE_MAP_ALL_ACCESS,//read/write permission 0, 0, 0); If (pbufs==NULL) {IErr=GetLastError (); Printf (" Could not map to the view of the file (% d). \ n ", iErr); break; } For (LONG I=0; i{((BYTE *) pbufs) [I]=(BYTE) I; } Printf (" Write done \ n "); _getch (); } while (0); If (pbufs!=NULL) {UnmapViewOfFile (pbufs); Pbufs=NULL; } If (hMapFile!=NULL) {The CloseHandle (hMapFile); HMapFile=NULL; } Return iErr; }
Page link:https//www.codepudding.com/Softwareengineering/78150.html