简体   繁体   English

这是我可以为一个进程保留的最大内存吗?

[英]Is this the max memory I can reserve for a process?

char bytes[0x7FFFFFFF]; /* this? */

int main()
{
    return 0;
}

Over 2Gb? 超过2Gb? (if i calc it right) (如果我计算正确)

I'm in a 32bit system, with 4Gb of memory. 我在32位系统中,具有4Gb内存。 In a different system that would be more or less? 在不同的系统中或多或少?

First off, this is going to be dependent on a number of factors like platform and even configuration on the platform. 首先,这将取决于许多因素,例如平台,甚至平台上的配置。 The max address space available to a 32-bit process is typically restricted by where the user/kernel space split is, which often is either 3G/1G or 2G/2G (user/kernel). 用户/内核空间划分的位置通常限制了32位进程可用的最大地址空间,通常是3G / 1G或2G / 2G(用户/内核)。

Now, likely creating an array like that won't actually "reserve" all that memory. 现在,可能创建这样的数组实际上不会“保留”所有内存。 Rather it would be mapped into the virtual address space and wouldn't actually start consuming memory until it's accessed (see: on demand paging). 而是将其映射到虚拟地址空间中,直到访问它为止才真正开始消耗内存(请参阅:按需分页)。

Also, remember that you have to share your address space with everything else in your program, including the code. 另外,请记住,您必须与程序中的所有其他内容(包括代码)共享地址空间。 If you consumed all of that with an array, where would your code go? 如果使用数组消耗了所有这些代码,那么代码将流向何处?

It depends by: 它取决于:

  • the compiler 编译器
  • the system 系统
  • the OS 操作系统

If you're running on win32, you are not even using your 4GB or RAM! 如果您在Win32上运行,则甚至没有使用4GB或RAM!

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

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