Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something special you have to do to get large chunks of memory on Windows or in Visual Studio?

This is the call I am making.

table  = (int *) malloc(sizeof(int) * (C+1) * (N+1));

C+1*N+1 comes out to be 657,562,500

But this call is returning a NULL for me when executed on Windows (indicating it could not allocate that amount of space).
(it works fine with a smaller number and also works fine with larger numbers than this on my Linux box)

The program doesn't really do much before this.

When I look at Task Manager it shows 28.1 GB of available memory.

So I am wondering, is there something I can set in Visual Studio like a compiler flag or something that will allow me to grab large chunks of memory like this?

If my math is correct I believe I am asking for about 1.22GB.

Appreciate any help

Edit: So apparently I need to run this as a 64-bit application. Anyone know how to change a c project to 64-bits in visual studio? In configuration parameters under platform Win32 is the only option.

like image 882
Dalupus Avatar asked Mar 20 '23 18:03

Dalupus


2 Answers

You likely have your project settings set to build a 32-bit Application.

While your computer may have tons of free memory, a 32-bit application cannot use more than 2GB. By my estimate, 4 bytes x 650M is around 2.6 GB.

Try changing your project settings to build for a 64-bit platform.

But still ask yourself why you're allocating so much memory at once. That could well indicate a program design problem.

like image 132
abelenky Avatar answered Apr 25 '23 09:04

abelenky


Too long and involved to make it a comment, so here's how you build it as 64-bit on Visual Studio. I'm on a laptop with VS 2010 rather than 2012, so I may have some details wrong, but this will get you there on 2010 or 2012.

From the IDE, do:

Build / Configuration Manager / Active Solution Platform / New... 

Choose the options shown below. Now you'll be able to build as 64-bit.

enter image description here

like image 35
Carey Gregory Avatar answered Apr 25 '23 09:04

Carey Gregory