打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
C#程序最大可使用的内存
进程可使用内存数就是操作系统给进程分配的最大地址,一般的32位操作系统提供给用户地址最大都是3g(操作系统自己保留1g),windows由于商业目的,对于个人用户只提供了2g地址,要使用3g扩展需要对系统配置作修改。还有就是intel的32位芯片实际上是支持36位寻址能力的(64g),但是也是出于商业目的对于大部分个人芯片都禁止了这个功能,这个禁止可能是物理上的限制个人用户几乎无法修改。
而且在操作系统中物理可用内存和进程实际占用内存是有区别的,因为有虚拟地址和交换区这种概念,进程实际使用的内存量远远大于物理可用内存,最简单的一个例子就是声明一个非常大的数组但不存放任何东西,进程启动后占用的物理内存可能很小但是申请的内存地址却是非常大了(虚拟内存数),所以就可能产生这么一种情况:空闲物理内存很多进程所占物理内存很小但却报了内存不够,因为进程可用地址已经完全被分配完了(申请很多,却没有用。所以要JIT,lazy...)。
====================================
有些时候由于代码的问题(确切地说是不了解framework的内存使用机制)也会导致outofmemory,一般占用大内存的情况就是list和hashtable2种结构,而这2种数据结构实际上都是使用数组作为容器存放元素的,由于数组是定长结构所以当达到上限时需要做动态扩容,动态扩容的算法都是2倍当前数组长度,数组本身又是需要连续内存作为保证,如果内存碎片过多就会导致没有连续内存可用,.net的智能垃圾回收器也没办法完全避免内存碎片(可以通过禁止垃圾回收或者降低垃圾回收频率来避免碎片,但是需要手工回收来解决内存增长问题),所以在使用list或者hashtable的时候最好能事先指定需要的最大容量上限,避免到后面因为碎片问题导致outofmemory。比如申请的初始内存块不够大,后期要分配更大内存,在本块内存区后面没有这么大的连续空闲内存,就会outofmemory。
=====================================
Chat Question: Memory Limits for 32-bit and 64-bit processes
During our recent blog chat, there were a number of topics that were asked about and I am going to expand on some of them.  The first one is the memory limits for different processes.
This really depends on a few different things.  The architecture of the process (32-bit or 64-bit) and also the architecture of the Operating System the process is running on.  For 32-bit it also depends if you use the /3GB switch or not.
So I broke this up based on these things into the table below, this is the maximum amount of memory available for the process assuming you have that much RAM and Pagefile space.
32-bit OS
64-bit OS
32-bit process
2 GB
4 GB
32-bit process with /3GB
3 GB
N/A
64-bit process
N/A
16 TB
These process numbers are contingent on how much RAM and disk space you have, so if you have 4 GB of RAM(内存) and 4 GB Pagefile(虚拟内存), the total memory of all running processes can’t be greater then 8 GB.
Note: If you let Windows manage your Pagefile size, when you hit this limit, Windows will try to grow your Pagefile as long as there is disk space available.
For the amount a .NET application will use before we can expect to see out of memory, those numbers are:
32-bit OS
64-bit OS
32-bit process
800-1200 MB
2800 MB
32-bit process with /3GB
1800 MB
N/A
64-bit process
N/A
2800 MB if using a 4 GB process or more if more RAM (around 70% of RAM + Pagefile)
Keep in mind that although a .NET process can grow this large, if the process is multiple GB in size, it can become very difficult for the Garage Collector to keep up with the memory as Generation 2 will become very large.  I’ll talk about the generations more in an upcoming post.
Hopefully that will clear up how much memory each one uses.
Keep checking the RECAP- ASP.NET Blog Chat to see other topics that Tess or I write about.
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
计算机内存取证技术
MemoryRead Delphi写的内存搜索与 读写操作库指定进程,在 中查找对应的字符与 串,或 VCL 182万源代码下载
最小化后释放内存
[Visual Studio] — Differences between x86, x64 and...
LoadRunner性能测试指标分析
VC 监控进程内存使用情况
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服