32 位 Windows 上的 C++ 应用程序可用的最大内存是多少? [英] What is the maximum memory available to a C++ application on 32-bit Windows?

查看:41
本文介绍了32 位 Windows 上的 C++ 应用程序可用的最大内存是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道 C++ 应用程序使用的最大内存是否有限制

Just wondering if there is a restriction on the max memory that a C++ application uses

我知道这是 2GB - 对吗?

I understand that this is 2GB - Is that correct?

如果 C++ 应用程序尝试请求超过 2GB 的内存,这是否会导致内存崩溃?

If a C++ app tries to request more then 2GB memory does this cause a memory crash?

最后一个问题 - 如果运行 C++ 应用程序的机器内存已经很低,而 C++ 应用程序要求 100MB 的数组(即连续内存),操作系统是否会通过使用虚拟内存来适应这一点?

Final question - If the machine the C++ app is running on is already low on memory and a C++ app asks for 100MB of array (ie contiguous memory) will the OS accommodate this by using virtual memory?

推荐答案

它会导致动态内存分配失败,这通常会导致应用程序崩溃,但从技术上讲,可以编写一个应用程序来承受此事件.2GB 确实是单个进程的用户地址空间大小——一个应用程序可以使用多个进程(最简单的例子:Chrome).如果应用程序要求 100MB 的连续内存,则该内存必须实际上是连续的,即使不是物理连续的,如果没有足够的连续页面可用,则分配失败.

It will cause a dynamic memory allocation failure, which usually will make the resultant application crash, but technically, an application could be written to withstand this event. 2GB is indeed the user address space size for an individual process- an application may use multiple processes (easiest example: Chrome). If an application asks for 100MB of contiguous memory, that memory must be virtually contiguous even if not physically contiguous, and if there aren't enough contiguous pages available then it's a failed allocation.

始终使用虚拟内存-所有内存都是虚拟的.

Virtual memory is always used- all memory is virtual.

2GB 是大多数情况下的限制.通常情况下,2GB 用于用户,2GB 用于内核,但您可以要求 Windows 为用户提供 3GB,为内核提供 1GB(有一定风险),并且在 64 位上,整个 4GB 的 32 位地址空间可供用户使用.仅当您将应用程序编译为 /LARGEADDRESSAWARE 时,增加的地址空间才可用.

2GB is the limit under most circumstances. What happens is that normally, 2GB is for the user and 2GB for the kernel, but you can ask Windows to make this 3GB for the user and 1GB for the kernel (at some risk), and on 64bit, the whole 4GB of 32bit address space is available to the user. The increased address space is only available if you compile your application as /LARGEADDRESSAWARE.

这篇关于32 位 Windows 上的 C++ 应用程序可用的最大内存是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆