xboxscene.org forums

Author Topic: Virtual Memory Allocation On The Xbox  (Read 82 times)

HCl

  • Archived User
  • Newbie
  • *
  • Posts: 34
Virtual Memory Allocation On The Xbox
« on: October 12, 2004, 07:21:00 AM »

Hey,

I'm trying to use VirtualAlloc to use virtual memory instead of physical,
since i don't have enough physical ram for my application,
but it seems to just allocate both physical and virtual memory, and runs out of
physical ram anyways... does anybody know what i'm doing wrong?

i'm using

   pointer=VirtualAlloc(NULL,size, MEM_COMMIT, PAGE_READWRITE );

i tried

   pointer=VirtualAlloc(NULL,size, MEM_RESERVE, PAGE_READWRITE );

as well, but that just crashes my program.

Does anybody know the proper way to allocate virtual memory?
Logged

BenJeremy

  • Archived User
  • Hero Member
  • *
  • Posts: 5645
Virtual Memory Allocation On The Xbox
« Reply #1 on: October 12, 2004, 08:59:00 AM »

There is no virtual memory system in the Xbox XDK libs, AFAIK.

I believe you have to implement your own system.
Logged

HCl

  • Archived User
  • Newbie
  • *
  • Posts: 34
Virtual Memory Allocation On The Xbox
« Reply #2 on: October 12, 2004, 09:17:00 AM »

oi, that sucks.
thanks..
i might be able to use the virtual memory manager of mameox... but ugh..
i'd rather find a different solution than having to write my own memory manager..
Logged

The unProfessional

  • Archived User
  • Hero Member
  • *
  • Posts: 679
Virtual Memory Allocation On The Xbox
« Reply #3 on: October 12, 2004, 10:39:00 PM »

BenJeremy:  Are the Xbox docs incorrect?  They include the VirtualAlloc* and VirtualFree* function calls.  Are they deprecated?
Logged

HCl

  • Archived User
  • Newbie
  • *
  • Posts: 34
Virtual Memory Allocation On The Xbox
« Reply #4 on: October 13, 2004, 02:29:00 AM »

no.. from what i kind of read and deducted from the virtual memory manager
in mameox... they simply allow you control over what pages from virtual memory
are currently in memory, and allow you to swap them back to virtual memory...
Logged

BenJeremy

  • Archived User
  • Hero Member
  • *
  • Posts: 5645
Virtual Memory Allocation On The Xbox
« Reply #5 on: October 13, 2004, 05:21:00 AM »

OK... upon futher review, it appears that the VirtualAlloc functions are basically a sham, used for compatibility, I'd guess. The important thing here is looking at the blurb in the doco about "Demand Paging" - which is the meat of any "real" virtual memory code. They basically state that they expect the developer to handle paging memory in and out of physical RAM, using their own system, for performance issues.

HCI: Yeah, I suspect any VirtMem functionality out there is going to be rather simple. For emus, the task is a bit easier, since you control the "memory" interface, as it's emulated and addressing is entirely under the emu's control (from the perspective of the emulated processor).
Logged

The unProfessional

  • Archived User
  • Hero Member
  • *
  • Posts: 679
Virtual Memory Allocation On The Xbox
« Reply #6 on: October 13, 2004, 02:15:00 PM »

I'm no genius when it comes to this... so bear with me...

I was under the impression that demand paging was simply a kernel feature that swaps physical memory to disk when it's overrun.  Basically the way virtual memory works in windows.

But it does seem to me that the explicit allocation of virtual memory via VirtualAlloc is supported.  They use it in the "FastCPU" sample.  Although I don't have an xbox here to test it.

Please correct me if I'm wrong, because I have a serious problem on my hands if VirtualAlloc isn't supported on the Xbox.
Logged

The unProfessional

  • Archived User
  • Hero Member
  • *
  • Posts: 679
Virtual Memory Allocation On The Xbox
« Reply #7 on: October 13, 2004, 10:12:00 PM »

well if you allocate 64 megs on the heap, you're in trouble.  But VirtualAlloc should allocate virtual memory pages on the hard disk.  The XDK says it can address up to something like 4 or 6 gigs of virtual address space.

Demand paging is different from explicity virtual memory allocation... or so I thought.
Logged

Mage

  • Archived User
  • Sr. Member
  • *
  • Posts: 482
Virtual Memory Allocation On The Xbox
« Reply #8 on: October 14, 2004, 04:28:00 AM »

The memory space is 4GB, meaning you can allocate memory anywhere in that space however you cannot exceed 64MB without running into problems.

The xdk states the kernel doesn't page to the hard drive due to the performance hit.
Logged