vs中 最大能new多少内存而不报错

hustlaofan 2011-10-11 05:08:49
如题
...全文
1024 22 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
hustlaofan 2011-10-12
  • 打赏
  • 举报
回复
还有1G的地址好像给显存占用了
hustlaofan 2011-10-12
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 keiy 的回复:]

引用 17 楼 hustlaofan 的回复:
我的32位xp,2G内存,结果为1912(M),系统不要内存了?

申请到的是虚存,不是物理内存
windows 32位操作系统物理内存最大支持3G
内部内存管理中,虚似内存可达4G
内存管理全表
Memory type Limit in on X86 Limit in 64-bit Windows
User-mode virtua……
[/Quote]
3Q
大道曙光 2011-10-12
  • 打赏
  • 举报
回复
学习了[Quote=引用 8 楼 bokutake 的回复:]

32位虚拟内存空间有4GB,进程自己可用的内存空间是2GB,其余2GB给系统内核。
但是排除应用程序自己用的一部分,new能分配的最多约1.5GB。
你400MB就不行了,是因为你的物理内存太小,导致你的程序耗光物理内存,而使系统其它进程不得被交换到硬盘上的页面文件,这样反复交换会导致速度减慢。
不过一般来说10MB以上的数据,尤其是整齐的数据,最好用VirtualAlloc分配内存页来用……
[/Quote]
柯本 2011-10-12
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 hustlaofan 的回复:]
我的32位xp,2G内存,结果为1912(M),系统不要内存了?
[/Quote]
申请到的是虚存,不是物理内存
windows 32位操作系统物理内存最大支持3G
内部内存管理中,虚似内存可达4G
内存管理全表
Memory type Limit in on X86 Limit in 64-bit Windows
User-mode virtual address space for each 32-bit process 2 GB
Up to 3 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE and 4GT 2 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE cleared (default)
4 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE set
User-mode virtual address space for each 64-bit process Not applicable With IMAGE_FILE_LARGE_ADDRESS_AWARE set (default):
x64: 8 TB
Intel IPF: 7 TB
2 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE cleared
Kernel-mode virtual address space 2 GB
From 1 GB to a maximum of 2 GB with 4GT 8 TB
Paged pool Limited by available kernel-mode virtual address space or the PagedPoolLimit registry key value.
Windows Vista and above: Limited only by kernel mode virtual address space. Starting with Windows Vista with Service Pack 1 (SP1), the paged pool can also be limited by the PagedPoolLimit registry key value.
Windows Home Server and Windows Server 2003: 530 MB
Windows XP: 490 MB
Windows 2000: 350 MB 128 GB
Windows Server 2003 and Windows XP: Up to 128 GB depending on configuration and RAM.
Windows 2000: Not applicable
Nonpaged pool Limited by available kernel-mode virtual address space, the NonPagedPoolLimit registry key value, or physical memory.
Windows Vista: Limited only by kernel mode virtual address space and physical memory. Starting with Windows Vista with SP1, the nonpaged pool can also be limited by the NonPagedPoolLimit registry key value.
Windows Home Server, Windows Server 2003, and Windows XP/2000: 256 MB, or 128 MB with 4GT. 75% of RAM up to a maximum of 128 GB
Windows Vista: 40% of RAM up to a maximum of 128 GB.
Windows Server 2003 and Windows XP: Up to 128 GB depending on configuration and RAM.
Windows 2000: Not applicable
System cache virtual address space (physical size limited only by physical memory) Limited by available kernel-mode virtual address space or the SystemCacheLimit registry key value.
Windows Vista: Limited only by kernel mode virtual address space. Starting with Windows Vista with SP1, system cache virtual address space can also be limited by the SystemCacheLimit registry key value.
Windows Home Server, Windows Server 2003, and Windows XP/2000: 860 MB with LargeSystemCache registry key set and without 4GT; up to 448 MB with 4GT. Always 1 TB regardless of physical RAM
Windows Server 2003 and Windows XP: Up to 1 TB depending on configuration and RAM.
Windows 2000: Not applicable

Physical Memory Limits: Windows 7
The following table specifies the limits on physical memory for Windows 7.
Version Limit on X86 Limit on X64
Windows 7 Ultimate 4 GB 192 GB
Windows 7 Enterprise 4 GB 192 GB
Windows 7 Professional 4 GB 192 GB
Windows 7 Home Premium 4 GB 16 GB
Windows 7 Home Basic 4 GB 8 GB
Windows 7 Starter 2 GB

Physical Memory Limits: Windows Server 2008 R2
The following table specifies the limits on physical memory for Windows Server 2008 R2. Windows Server 2008 R2 is available only in 64-bit editions.
Version Limit on X64 Limit on IA64
Windows Server 2008 R2 Datacenter 2 TB
Windows Server 2008 R2 Enterprise 2 TB
Windows Server 2008 R2 for Itanium-Based Systems 2 TB
Windows Server 2008 R2 Foundation 8 GB
Windows Server 2008 R2 Standard 32 GB
Windows HPC Server 2008 R2 128 GB
Windows Web Server 2008 R2 32 GB

Physical Memory Limits: Windows Server 2008
The following table specifies the limits on physical memory for Windows Server 2008. Limits greater than 4 GB for 32-bit Windows assume that PAE is enabled.
Version Limit on X86 Limit on X64 Limit on IA64
Windows Server 2008 Datacenter 64 GB 1 TB
Windows Server 2008 Enterprise 64 GB 1 TB
Windows Server 2008 HPC Edition 128 GB
Windows Server 2008 Standard 4 GB 32 GB
Windows Server 2008 for Itanium-Based Systems 2 TB
Windows Small Business Server 2008 4 GB 32 GB
Windows Web Server 2008 4 GB 32 GB

Physical Memory Limits: Windows Vista
The following table specifies the limits on physical memory for Windows Vista.
Version Limit on X86 Limit on X64
Windows Vista Ultimate 4 GB 128 GB
Windows Vista Enterprise 4 GB 128 GB
Windows Vista Business 4 GB 128 GB
Windows Vista Home Premium 4 GB 16 GB
Windows Vista Home Basic 4 GB 8 GB
Windows Vista Starter 1 GB

Physical Memory Limits: Windows Home Server
Windows Home Server is available only in a 32-bit edition. The physical memory limit is 4 GB.
Physical Memory Limits: Windows Server 2003 R2
The following table specifies the limits on physical memory for Windows Server 2003 R2. Limits over 4 GB for 32-bit Windows assume that PAE is enabled.
Version Limit on X86 Limit on X64
Windows Server 2003 R2 Datacenter Edition 64 GB
(16 GB with 4GT) 1 TB
Windows Server 2003 R2 Enterprise Edition 64 GB
(16 GB with 4GT) 1 TB
Windows Server 2003 R2 Standard Edition 4 GB 32 GB

Physical Memory Limits: Windows Server 2003 with Service Pack 2 (SP2)
The following table specifies the limits on physical memory for Windows Server 2003 with SP2. Limits over 4 GB for 32-bit Windows assume that PAE is enabled.
Version Limit on X86 Limit on X64 Limit on IA64
Windows Server 2003 with Service Pack 2 (SP2), Datacenter Edition 64 GB
(16 GB with 4GT) 1 TB 2 TB
Windows Server 2003 with Service Pack 2 (SP2), Enterprise Edition 64 GB 1 TB 2 TB
Windows Server 2003 with Service Pack 2 (SP2), Standard Edition 4 GB 32 GB

Physical Memory Limits: Windows Server 2003 with Service Pack 1 (SP1)
The following table specifies the limits on physical memory for Windows Server 2003 with SP1. Limits over 4 GB for 32-bit Windows assume that PAE is enabled.
Version Limit on X86 Limit on X64 Limit on IA64
Windows Server 2003 with Service Pack 1 (SP1), Datacenter Edition 64 GB
(16 GB with 4GT) X64 1 TB 1 TB
Windows Server 2003 with Service Pack 1 (SP1), Enterprise Edition 64 GB
(16 GB with 4GT) X64 1 TB 1 TB
Windows Server 2003 with Service Pack 1 (SP1), Standard Edition 4 GB 32 GB

Physical Memory Limits: Windows Server 2003
The following table specifies the limits on physical memory for Windows Server 2003. Limits over 4 GB for 32-bit Windows assume that PAE is enabled.
Version Limit on X86 Limit on IA64
Windows Server 2003, Datacenter Edition 64 GB
(16 GB with 4GT) 512 GB
Windows Server 2003, Enterprise Edition 64 GB
(16 GB with 4GT) 512 GB
Windows Server 2003, Standard Edition 4 GB
Windows Server 2003, Web Edition 2 GB
Windows Small Business Server 2003 4 GB
Windows Compute Cluster Server 2003 32 GB
Windows Storage Server 2003, Enterprise Edition 8 GB
Windows Storage Server 2003 4 GB

Physical Memory Limits: Windows XP
The following table specifies the limits on physical memory for Windows XP.
Version Limit on X86 Limit on X64 Limit on IA64
Windows XP 4 GB 128 GB 128 GB (not supported)
Windows XP Starter Edition 512 MB

Physical Memory Limits: Windows 2000
The following table specifies the limits on physical memory for Windows 2000.
Version Limit on X86
Windows 2000 Professional 4 GB
Windows 2000 Server 4 GB
Windows 2000 Advanced Server 8 GB
Windows 2000 Datacenter Server 32 GB


pathuang68 2011-10-12
  • 打赏
  • 举报
回复
new到底可以有多大和编译器以及操作系统有关。其中最直接的关系是编译器。

一般在32bit的windows上,一个进程最大可用的内存是2G,除去一些系统本身需要的内存占用,实际上通常会低于这个数字。

真正意义的64bit系统上,理论上可以new出2^63bit,总之应该是一个非常大的数字。但现在64bit相关的很多方面还不是特别成熟,所以得到的结果很有可能是五花八门的,但肯定会比32bit上的大。
malone1 2011-10-12
  • 打赏
  • 举报
回复
可以设置一下。应该能到3G
hustlaofan 2011-10-12
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 menzi11 的回复:]

引用 15 楼 hustlaofan 的回复:

32位xp或者win7都只能用3G内存,就算你有4G内存,为什么呢


应该是32位寻址的问题吧,前几年有几个工具可以让32位系统用满4g



回楼主,虽然你32位系统能用到3G理论上,但是由于有内存碎片,
你申请个数组,要求内存是连续排列的,假如你有3G的内存,我在
1.5G的位置写一个char,你就申请不了连续的3G了……
[/Quote]
内存碎片不要我们管,而且在不用汇编的情况下,似乎你不能在1.5G的位置上写一个char,汇编也没那么大的寻址,在vs环境下是可以new到接近2G的连续内存的
hustlaofan 2011-10-12
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 keiy 的回复:]

自己测试下:
C/C++ code

#include <iostream>
using namespace std;
int main()
{
char *p;
int i=0;
try
{
do
{
p=new char[1024*1024]; //每次1M
i++;
} while(p);
}
catch……
[/Quote]
我的32位xp,2G内存,结果为1912(M),系统不要内存了?
menzi11 2011-10-12
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 hustlaofan 的回复:]

32位xp或者win7都只能用3G内存,就算你有4G内存,为什么呢
[/Quote]

应该是32位寻址的问题吧,前几年有几个工具可以让32位系统用满4g



回楼主,虽然你32位系统能用到3G理论上,但是由于有内存碎片,
你申请个数组,要求内存是连续排列的,假如你有3G的内存,我在
1.5G的位置写一个char,你就申请不了连续的3G了...
hustlaofan 2011-10-12
  • 打赏
  • 举报
回复
32位xp或者win7都只能用3G内存,就算你有4G内存,为什么呢
zhengjiankang 2011-10-12
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 bokutake 的回复:]

32位虚拟内存空间有4GB,进程自己可用的内存空间是2GB,其余2GB给系统内核。
但是排除应用程序自己用的一部分,new能分配的最多约1.5GB。
你400MB就不行了,是因为你的物理内存太小,导致你的程序耗光物理内存,而使系统其它进程不得被交换到硬盘上的页面文件,这样反复交换会导致速度减慢。
不过一般来说10MB以上的数据,尤其是整齐的数据,最好用VirtualAlloc分配内存页来用……
[/Quote]

在windows上面
进程的4G的虚拟内存带内核使用的只有2G的吧。
另外2G的好像是内存映射文件使用的。
理论的虚拟内存地址范围是0x7FFFFFFF以下的。
里面还包括空指针地址。内核内存地址。等等
具体new的内存理论最大值肯定是小于2G的。
个人比较赞成12楼的。
fcly1981826ly 2011-10-11
  • 打赏
  • 举报
回复
学习,,,
柯本 2011-10-11
  • 打赏
  • 举报
回复
自己测试下:

#include <iostream>
using namespace std;
int main()
{
char *p;
int i=0;
try
{
do
{
p=new char[1024*1024]; //每次1M
i++;
} while(p);
}
catch(...)
{
}
cout << i <<endl;
}

在xp 下,结果为1906(M)
在win7 64位下,32位编译器:1868(M)
在win7 64位下,64位编译器:5488(M)

独酌逸醉 2011-10-11
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 bokutake 的回复:]

32位虚拟内存空间有4GB,进程自己可用的内存空间是2GB,其余2GB给系统内核。
但是排除应用程序自己用的一部分,new能分配的最多约1.5GB。
你400MB就不行了,是因为你的物理内存太小,导致你的程序耗光物理内存,而使系统其它进程不得被交换到硬盘上的页面文件,这样反复交换会导致速度减慢。
不过一般来说10MB以上的数据,尤其是整齐的数据,最好用VirtualAlloc分配内存页来用……
[/Quote]

++
辰岡墨竹 2011-10-11
  • 打赏
  • 举报
回复
32位虚拟内存空间有4GB,进程自己可用的内存空间是2GB,其余2GB给系统内核。
但是排除应用程序自己用的一部分,new能分配的最多约1.5GB。
你400MB就不行了,是因为你的物理内存太小,导致你的程序耗光物理内存,而使系统其它进程不得被交换到硬盘上的页面文件,这样反复交换会导致速度减慢。
不过一般来说10MB以上的数据,尤其是整齐的数据,最好用VirtualAlloc分配内存页来用。new适合零碎的小=段数据。
quwei197874 2011-10-11
  • 打赏
  • 举报
回复
32位下理论上最大4G
turing-complete 2011-10-11
  • 打赏
  • 举报
回复
听说过内存碎片嘛
zhongrihan2008 2011-10-11
  • 打赏
  • 举报
回复
和你的机器有关系的,不同的机器不同!
hustlaofan 2011-10-11
  • 打赏
  • 举报
回复
貌似大于400M就不行了,不知道具体是什么原理
iamnobody 2011-10-11
  • 打赏
  • 举报
回复
真到没有足够的空间为止
加载更多回复(2)

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧