简体   繁体   English

如何使C ++程序使用超过4GB的RAM?

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

My desktop is 64bit and has 16gb ram. 我的桌面是64位的,并具有16GB内存。

Is there a compile time setting to enable run? 是否有编译时间设置来启用运行? Or a runtime? 还是运行时?

You are running Linux. 您正在运行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. 如果这不起作用,则最有可能的问题是,尽管有一台x86_64机器,但是尽管已在具有64位功能的处理器上安装了32位版本的OS。 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. 如果您使用的是64位版本的操作系统,则编译器工具链应自动生成可以使用超过4GB内存的代码。

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 . 请注意, x86_64不是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. 从理论上讲,您可以从i386x86_64交叉编译,但在大多数情况下,这样做并不麻烦,您将需要重新安装。

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. 对于虚拟内存,您只需将代码编译为64位应用程序,您的程序自然就会拥有多达2 ^ 64GB的虚拟内存。

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. 如果有足够的物理内存可用,并且您已经使用了超过4GB的虚拟内存,则您的程序很可能也占用了超过4GB的物理内存。

64 bit flag for gcc is -m64. gcc的64位标志是-m64。

If your machine is 64 bit it is the default, and you'll need to give the -m32 to compile 32 bit version. 如果您的计算机是64位,则它是默认设置,并且您需要提供-m32来编译32位版本。

If you want more info look here 如果您想了解更多信息,请点击这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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