Allocating very large memory
-
Hello, I am facing with a problem while trying to allocate very large memory by AWE APIs on Windows 2003 Advanced Server. I developed following code in order to allocate large memory portion, but I couldn't allocate it; #include "stdafx.h" #define _WIN32_WINNT 0x0500 #include #include #define MEM_ALLOC 1024 * 1024 * 1024 * 4 // allocate physical memory int _tmain(int argc, _TCHAR* argv[]) { struct { DWORD count; LUID_AND_ATTRIBUTES privilege[1]; } info; HANDLE token=0x0; BOOL result=FALSE; int iPageCount=0x0; int PFNarraysize=0x0; ULONG_PTR NumberOfPages=0x0; ULONG_PTR* PFNarraylist=0x0; SYSTEM_INFO sys_info; PVOID lpMemoryWindow=0x0; // get system page size GetSystemInfo(&sys_info); // calculate how many pages required iPageCount = MEM_ALLOC / sys_info.dwPageSize; // PFN requested size PFNarraysize = iPageCount * sizeof(ULONG_PTR); // allocate array for PFN array PFNarraylist = (ULONG_PTR*)HeapAlloc(GetProcessHeap(), 0, PFNarraysize); // ------------------------------------------------------------- // // check user privileges in order to lock memory on the system result = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token); // set privilege attributes info.privilege[0].Attributes = SE_PRIVILEGE_ENABLED; // lookup user privileges result = LookupPrivilegeValue(NULL, SE_LOCK_MEMORY_NAME, &(info.privilege[0].Luid)); // info count info.count=0x1; // retrieve user privilege result = AdjustTokenPrivileges(token, FALSE, (PTOKEN_PRIVILEGES)&info, 0, NULL, NULL); // close token handle CloseHandle(token); // ------------------------------------------------------------- // // create memory window lpMemoryWindow=VirtualAlloc(NULL, MEM_ALLOC, MEM_RESERVE | MEM_PHYSICAL, PAGE_READWRITE); NumberOfPages = iPageCount; // allocate physical memory - I result = AllocateUserPhysicalPages(GetCurrentProcess(), &NumberOfPages, PFNarraylist); // map user physical page to the window - I result = MapUserPhysicalPages(lpMemoryWindow, iPageCount, PFNarraylist); // use memory lstrcpy((LPSTR)lpMemoryWindow, TEXT("OGED")); } In the example that I wrote above can allocate 2 gb or less memory but not more and I am sure that I have 16 Gb physical memory. How can I allocate and use more than 4 Gb memory? Can anybody give an example about AWE? PS: I am aware about MSDN AWE and MSDJ - 99 examples, but they are not a solution for my case. Regards, Orkun GEDiK SAP R/3 Software
-
Hello, I am facing with a problem while trying to allocate very large memory by AWE APIs on Windows 2003 Advanced Server. I developed following code in order to allocate large memory portion, but I couldn't allocate it; #include "stdafx.h" #define _WIN32_WINNT 0x0500 #include #include #define MEM_ALLOC 1024 * 1024 * 1024 * 4 // allocate physical memory int _tmain(int argc, _TCHAR* argv[]) { struct { DWORD count; LUID_AND_ATTRIBUTES privilege[1]; } info; HANDLE token=0x0; BOOL result=FALSE; int iPageCount=0x0; int PFNarraysize=0x0; ULONG_PTR NumberOfPages=0x0; ULONG_PTR* PFNarraylist=0x0; SYSTEM_INFO sys_info; PVOID lpMemoryWindow=0x0; // get system page size GetSystemInfo(&sys_info); // calculate how many pages required iPageCount = MEM_ALLOC / sys_info.dwPageSize; // PFN requested size PFNarraysize = iPageCount * sizeof(ULONG_PTR); // allocate array for PFN array PFNarraylist = (ULONG_PTR*)HeapAlloc(GetProcessHeap(), 0, PFNarraysize); // ------------------------------------------------------------- // // check user privileges in order to lock memory on the system result = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token); // set privilege attributes info.privilege[0].Attributes = SE_PRIVILEGE_ENABLED; // lookup user privileges result = LookupPrivilegeValue(NULL, SE_LOCK_MEMORY_NAME, &(info.privilege[0].Luid)); // info count info.count=0x1; // retrieve user privilege result = AdjustTokenPrivileges(token, FALSE, (PTOKEN_PRIVILEGES)&info, 0, NULL, NULL); // close token handle CloseHandle(token); // ------------------------------------------------------------- // // create memory window lpMemoryWindow=VirtualAlloc(NULL, MEM_ALLOC, MEM_RESERVE | MEM_PHYSICAL, PAGE_READWRITE); NumberOfPages = iPageCount; // allocate physical memory - I result = AllocateUserPhysicalPages(GetCurrentProcess(), &NumberOfPages, PFNarraylist); // map user physical page to the window - I result = MapUserPhysicalPages(lpMemoryWindow, iPageCount, PFNarraylist); // use memory lstrcpy((LPSTR)lpMemoryWindow, TEXT("OGED")); } In the example that I wrote above can allocate 2 gb or less memory but not more and I am sure that I have 16 Gb physical memory. How can I allocate and use more than 4 Gb memory? Can anybody give an example about AWE? PS: I am aware about MSDN AWE and MSDJ - 99 examples, but they are not a solution for my case. Regards, Orkun GEDiK SAP R/3 Software
You do not say it or not, but are you booting with the
/PAE
switch? You need it to enable applications to address at and above 4GB. Normally, you can only address 2GB unless you booted with the/3GB
switch. Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -
You do not say it or not, but are you booting with the
/PAE
switch? You need it to enable applications to address at and above 4GB. Normally, you can only address 2GB unless you booted with the/3GB
switch. Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!)Hello, Sorry, I forgot to say that, "I am using /PAE switch already". Regards, Orkun GEDiK SAP R/3 Software & System Support Specialist ASTRON