Mich
Mich

Reputation: 300

C how to allocate more than 2GB of memory

I am using code::blocks to compile a C program. The PC is: Windows 8.2 64b with 32GB of RAM + 32GB of swap if needed. I need 24GB to store intermediate values to have the program running fast enough (around X12 faster).

I need to allocate around 240 blocks of 100MB each. The malloc returns NULL at the 19th block (there are some other small blocks) so total is 2GB.

Is there a way to compile/link the program to be able to allocate this memory? An other tool than code::blocks? (I did it with Matlab, it works fine, no problem of memory but Matlab is really slower than compiled C).

Best regards. Mich.

Upvotes: 0

Views: 927

Answers (1)

Lundin
Lundin

Reputation: 213321

You need to build it as a 64 bit application, since 32 bit Windows applications have a restricted amount of 4 Gb addressable memory, lots of that being reserved for OS etc. Also, I don't think MinGW 32 bit is maintained any longer(?)

  • Download and install Mingw64. http://mingw-w64.org
  • In Codeblocks, Settings -> Compiler, pick the Toolchain executables tab.
  • Specify the path, something like C:\Program Files\mingw-w64... (wherever you installed it)
  • Click the button "auto detect". All gcc paths and tools should now be updated to point at the 64 bit installation. C compiler should be something like "x86_64-w64-mingw32-gcc.exe".

Upvotes: 1

Related Questions