Home > Software engineering >  Why this error? The Shared memory is set to 0
Why this error? The Shared memory is set to 0

Time:11-06



No problem when the Shared memory size set to 1024, when set to 10 * 1024 in meset error here, why?

CodePudding user response:

The
refer to the original poster ForgetTomorrow response:


No problem when the Shared memory size set to 1024, when set to 10 * 1024 in meset error here, why?

Debugging found only 4 * 1024 size, again big

CodePudding user response:

According to the integer times of system page 1, 2 the returned handle & amp; Buffer pointer to determine whether effective

SYSTEM_INFO sysInfo.
GetNativeSystemInfo (& amp; The sysInfo);
Int BUF_SIZE=102400 * sysInfo. DwPageSize;


CodePudding user response:

refer to the second floor zgl7903 response:
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;


To the 4096 crash

CodePudding user response:

Windows system has to the Shared memory size limit? I can only be set to 1 KB, greater than 1 KB access errors

CodePudding user response:

 


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;
}





  • Related