在wince系统中,除去系统运行的内存后,剩余的内存分为存储内存与程序内存。
存储内存顾名思义即为存储用的内存,非存储器件空间下所放置的文件就在存储内存中;
程序内存即为程序可用的内存空间;
通常存储内存与程序内存在系统定制时就已经固定,在系统之上只能手动修改控制面板达到动态分配的目的,不是很方便。 在此提供一种代码控制程序内存与存储内存分配的方法,直接上代码:
-
HINSTANCE hDll = LoadLibrary(_T("Coredll.dll"));
-
SETSYSTEMMEMORYDIVISION SetSystemMemoryDivisionProc = NULL;
-
GETSYSTEMMEMORYDIVISION GetSystemMemoryDivisionProc = NULL;
-
if( NULL != hDll )
-
{
-
//获取导出函数地址
-
SetSystemMemoryDivisionProc = (SETSYSTEMMEMORYDIVISION)GetProcAddress(hDll,_T("SetSystemMemoryDivision"));
-
GetSystemMemoryDivisionProc = (GETSYSTEMMEMORYDIVISION)GetProcAddress(hDll,_T("GetSystemMemoryDivision"));
-
-
if(SetSystemMemoryDivisionProc && GetSystemMemoryDivisionProc)
-
{
-
DWORD dwStorePages = 0;
-
DWORD dwRamPages = 0;
-
DWORD dwPageSize = 0;
-
BOOL bRet = (*GetSystemMemoryDivisionProc)(&dwStorePages,&dwRamPages,&dwPageSize); //获取存储内存与物理内存大小
-
RETAILMSG(1,(TEXT("dwStorePages =0x%x , dwRamPages = 0x%x ,dwPageSize= %d\r\n"),dwStorePages,dwRamPages, dwPageSize));
-
if(bRet)
-
{
-
int nPageCount;
-
nPageCount = 368; //存储内存占用页
-
-
RETAILMSG(1,(TEXT("nPageCount= %d\r\n"), nPageCount));
-
(*SetSystemMemoryDivisionProc)(nPageCount); //设置
-
Sleep(222);
-
}
-
-
}
-
DWORD StorePages = 0;
-
DWORD RamPages = 0;
-
DWORD PageSize = 0;
-
-
BOOL Ret = (*GetSystemMemoryDivisionProc)(&StorePages,&RamPages,&PageSize); //获取存储内存与物理内存大小
-
RETAILMSG(1,(TEXT("StorePages =0x%x , RamPages = 0x%x ,PageSize= %d\r\n"),StorePages,RamPages, PageSize));
-
-
Sleep(200);
-
-
SetSystemMemoryDivisionProc = NULL;
-
GetSystemMemoryDivisionProc = NULL;
-
FreeLibrary(hDll);
-
hDll = NULL;
-
}
阅读(1956) | 评论(0) | 转发(0) |