简体   繁体   中英

How to make a C++ program use more than 4GB RAM?

My desktop is 64bit and has 16gb ram.

Is there a compile time setting to enable run? Or a runtime?

You are running Linux. If this is not working, the most likely problem is that despite having an x86_64 machine, you have installed a 32 bit version of the OS albeit on a 64 bit capable processor. If you have a 64 bit version of the OS, your compiler toolchain should automatically produce code that can use more than 4GB of memory.

To check, type:

uname -a

You should see something like:

Linux nimrod-ubuntu 3.13.0-29-generic #53~precise1-Ubuntu SMP Wed Jun 4 22:06:25 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Note the x86_64 not i386 .

Whilst you can in theory cross-compile from i386 to x86_64 , in most cases it's not worth the hassle and you will want to do a reinstall.

It depends on whether you are referring to virtual memory or physical memory.

For virtual memory, you simply compile your code as a 64-bit application and your program will naturally have up to 2^64GB virtual memory.

For physical memory, it depends on the OS to allocate how much memory for your program. If there are enough amount of physical memory available and you already use over 4GB virtual memory, it is very likely that your program is also occupying over 4GB physical memory.

64 bit flag for gcc is -m64.

If your machine is 64 bit it is the default, and you'll need to give the -m32 to compile 32 bit version.

If you want more info look here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM