Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Allocating very large memory

Allocating very large memory

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsssysadmindata-structuresperformance
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Orkun GEDiK
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • O Orkun GEDiK

      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

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #2

      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!)

      O 1 Reply Last reply
      0
      • J James R Twine

        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!)

        O Offline
        O Offline
        Orkun GEDiK
        wrote on last edited by
        #3

        Hello, Sorry, I forgot to say that, "I am using /PAE switch already". Regards, Orkun GEDiK SAP R/3 Software & System Support Specialist ASTRON

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups