1

I am running Windows-7-64 on a PC with 16GB RAM. I boot up the machine and launch Visual studio 2015. I also start up Resource monitor and it tells me my memory is arranged as follows:

Hardware reserved: 116MB In use: 2,917 MB Modified: 79MB Standby: 2,360MB Free: 10,912MB

I then execute this program I am developing in debug mode. The program attempts to malloc() 1,292,000,000 bytes and fails. This is right at the start of the program's operation. It is not doing any malloc()/free() operations beforehand. If I run the same program in release mode then it succeeds.

Any idea how to fix this?

Mick
  • 8,284
  • 22
  • 81
  • 173

1 Answers1

6

You are apparently doing a 32-bit build despite being on a 64-bit OS. You could make the application "large address aware" as Estiny suggested, for twice as much room. But if you want to work with gigabytes of data, you're better off switching to a 64-bit build.

JSF
  • 5,281
  • 1
  • 13
  • 20
  • Just trying to figure out how to set it to 64 bit - I'll report back when I've done it. – Mick Sep 06 '15 at 12:10
  • Google gave this as the first answer to setting 64 bit. It looks plausible (I don't have VS handy to double check) https://msdn.microsoft.com/en-US/library/ms185328.aspx – JSF Sep 06 '15 at 12:12
  • 1
    @JSF - Appreciating your answer but shouldn't he be able to allocate 2GB running as a 32bit application? – William Jones Sep 06 '15 at 12:34
  • @WilliamJones - You might be able to allocate a total *of up* to 2 GB, but are not guaranteed to be able to get it all in one block. The program code, for example, will likely use up some space. It is usual to hit a limit around 1.2-1.3 GB. – Bo Persson Sep 06 '15 at 13:27
  • @WilliamJones, without LargeAddressAware, a 32-bit app has just under 2GB total address space, but that space is fragmented by DLLs that load with the program. So you can't allocate a single chunk anywhere near the total. I don't have any guess which DLLs load where in the original build, so I wouldn't have predicted whether you could allocate a 1.2GB chunk. But given the fact it didn't work, I'm confident of the explanation that fragmentation of the 2GB total address space is the reason. In a 32-bit OS, LargeAddressAware might make no difference or increase to 3GB, in a 64bit OS, 4GB. – JSF Sep 06 '15 at 14:56
  • It was a battle to get it to compile and run as 64 bit... but it did the trick. – Mick Sep 06 '15 at 15:46