QA: How can I change memory allocated between storage and program programmatically?
Vassili Philippov (vasja@spbteam.com), September 17, 2001.
Question
I need to change memory division between storage and RAM like in the Main applet of
the Control Panel. How it can be done?
Answer
There is a SetSystemMemoryDivision function in coredll.dll library
for that. This function sets number of memory pages for storage. Use
GetSystemMemoryDivision function to get memory page size. Here are signatures
of these two functions:
typedef BOOL (__stdcall *GetSystemMemoryDivisionProc)(LPDWORD,LPDWORD,LPDWORD);
typedef DWORD (__stdcall *SetSystemMemoryDivisionProc)(DWORD);
SetSystemMemoryDivision
This function takes one argument - size of storage in memory pages. It returns result code
that could be:
-
0 - memory division was changes successfully
-
1 - need reboot to accept memory division changes
-
2 - cannot change memory division because the system should be rebooted after the previous call before
-
3 - changes failed. You can call GetLastError to get more detailed information
GetSystemMemoryDivision
This function returns 3 DWORD values and result code. The first parameter
is a pointer to a variable that will contain number of memory pages allocated for storage.
The second parameter is a pointer to a variable that will contain number of memory pages
allocated for RAM. The third parameter is a pointer to a variable that will contain size
of one memory page in bytes.
coredll.dll
To use these two functions you should load coredll.dll library using LoadLibrary
function and get functions addresses using GetProcAddress function. Here is a sample
code for that:
typedef BOOL (__stdcall *GetSystemMemoryDivisionProc)(LPDWORD,LPDWORD,LPDWORD);
typedef DWORD (__stdcall *SetSystemMemoryDivisionProc)(DWORD);
void ReadMemoryDivision()
{
HINSTANCE hCoreDll = LoadLibrary(_T("coredll.dll"));
GetSystemMemoryDivisionProc procGet =
(GetSystemMemoryDivisionProc)GetProcAddress(
hCoreDll, _T("GetSystemMemoryDivision"));
DWORD dwStoragePages;
DWORD dwRamPages;
DWORD dwPageSize;
BOOL bResult = procGet(&dwStoragePages, &dwRamPages, &dwPageSize);
FreeLibrary(hCoreDll);
}
void SetMemoryDivision()
{
int nStoragePages = GetNewStorageSize(); //Write your own source here
HINSTANCE hCoreDll = LoadLibrary(_T("coredll.dll"));
SetSystemMemoryDivisionProc procSet =
(SetSystemMemoryDivisionProc)GetProcAddress(
hCoreDll, _T("SetSystemMemoryDivision"));
DWORD dwResult = procSet(nStoragePages);
//Process result code
FreeLibrary(hCoreDll);
}
Emulator
Note: SetSystemMemoryDivision function does not work on Pocket PC Emulator.
Sample application
You can download a sample application (42 Kb) that shows working with SetSystemMemoryDivision and
GetSystemMemoryDivision functions.
Related resources:
-
http://www.pocketpcdn.com/sections/deviceinfo.html
Section: Device information
- http://support.microsoft.com/default.aspx?scid=kb;en-us;326163
Article: INFO: Understanding Windows CE DLL Load Failures
- http://support.microsoft.com/default.aspx?scid=kb;en-us;326162
Article: INFO: Address Space Layout of a Windows CE Process