Handmade Hero»Forums»Code
Devon
2 posts
Day 14 - VirtualAlloc not allocating properly
Hey all, I recently got started watching the Handmade Hero series.

I've followed up to the point where GameMemory.TransientStorage is allocated using Virtual Alloc. TransientStorageSize is correctly assigned at 4Gb but TransientStorage remains at 0 which I believe means that VirtualAlloc was unable to allocate 4Gb of memory.

I'm on a 64bit OS with a 64bit CPU. My system has 8Gb of RAM and only 2.9 is in use. So I should have around 5Gb(4659MB according to the Resource Monitor) to spare.

I'm just unsure of what is causing VirtualAlloc to decide there isn't 4Gb of space available causing it to return null instead of the base address. In fact, It won't allocate anything above 1Gb.

I can't think of anything other than a setting in Visual Studio that is causing the failure. I could use some help in this matter.
Mārtiņš Možeiko
2570 posts / 2 projects
Day 14 - VirtualAlloc not allocating properly
Edited by Mārtiņš Možeiko on
Are you compiling executable as 64-bit? If you compile executable as 32-bit, then even on 64-bit OS it won't be able to allocate 4GB chunk - probably anything above 1GB (or even less) will fail.
Devon
2 posts
Day 14 - VirtualAlloc not allocating properly
Edited by Devon on
I think this is the issue...I'm looking into it. I'm not sure if I somehow ended up with a 32bit version of Visual studio but it appears that way. So I'm checking to see if there was actually a 64bit version I just didn't download. I should be able to fix it and I'll check back when I do.

Silly me...

EDIT: Okay yea, that was the issue, just building as a 32bit application.

Since I'm using Visual Studio as my editor as well, for anybody who might have the same issue to fix go to Build->Configuration Manager.

Select the Dropdown for Platform-><new>.

x64 should be an option to select. Select x64 and then close out of the manager with x64 as the platform. Should work.
Mārtiņš Možeiko
2570 posts / 2 projects
Day 14 - VirtualAlloc not allocating properly
It doesn't matter what version is Visual Studio. Afaik it is available only as 32-bit.

If you use IDE to create project, you need to add "x64" configuration to your project. That will make compiler to compile to 64-bit code. "Win32" configuration is what creates 32-bit code.