简体   繁体   English

进程内存限制为64位进程

[英]Process Memory limit of 64-bit process

I currently have a 32-bit .Net application (on x86 Windows) which require lots of memory. 我目前有一个32位.Net应用程序(在x86 Windows上)需要大量内存。 Recently it started throwing System.OutOfMemoryException's. 最近它开始抛出System.OutOfMemoryException了。

So, I am planning to move it to a x64 platform as 64-bit process. 所以,我打算将它作为64位进程转移到x64平台。 So will this help with the out of memory exceptions. 因此,这将有助于内存不足异常。 I was reading this article from MSDN Memory limits for Windows 我正在从Windows的 MSDN 内存限制中阅读本文

So, my question is if I compile a 64bit .Net application, will it have IMAGE_FILE_LARGE_ADDRESS_AWARE set as default (As the article suggests)? 所以,我的问题是如果我编译64位.Net应用程序,它是否将IMAGE_FILE_LARGE_ADDRESS_AWARE设置为默认值(如文章所示)? ie will I be able to take advantage of the 8GB user-mode virtual address space? 即我能够利用8GB用户模式虚拟地址空间吗?

IMAGE_FILE_LARGE_ADDRESS_AWARE is only relevant for 32 bit processes. IMAGE_FILE_LARGE_ADDRESS_AWARE仅与32位进程相关。 The reason is that the address space on 32 bit Windows is split in two: 2 GB for kernel space and 2 GB for user space. 原因是32位Windows上的地址空间分为两部分:内核空间为2 GB,用户空间为2 GB。 To address 2 GB you need 31 bits. 要满足2 GB,您需要31位。 Ie the pointers in a 32 bit application do not need the last bit for addressing. 即32位应用程序中的指针不需要最后一位用于寻址。

Some applications may have used this extra bit for custom purposes, so if the Windows memory manager suddenly hands them a real 32 bit address they can't handle that. 某些应用程序可能已将此额外位用于自定义目的,因此如果Windows内存管理器突然向他们提供真正的32位地址,则无法处理。 By enabling the IMAGE_FILE_LARGE_ADDRESS_AWARE flag the application basically tells the OS that it can handle the entire 32 bit addressable space. 通过启用IMAGE_FILE_LARGE_ADDRESS_AWARE标志,应用程序基本上告诉操作系统它可以处理整个32位可寻址空间。

If you run a IMAGE_FILE_LARGE_ADDRESS_AWARE application on 32 bit Windows you can access 3 GB. 如果在32位Windows上运行IMAGE_FILE_LARGE_ADDRESS_AWARE应用程序,则可以访问3 GB。 If you run the same 32 bit application on 64 bit Windows the process actually gets the entire 4 GB address space. 如果在64位Windows上运行相同的32位应用程序,则该进程实际上会获得整个4 GB的地址空间。

If you run a 64 bit application on 64 bit Windows the user address space is 8 TB (with another 8 TB set aside for kernel address space). 如果在64位Windows上运行64位应用程序,则用户地址空间为8 TB(另外8 TB用于内核地址空间)。 .NET applications set to AnyCPU will automatically be 64 bit applications on x64, so you don't have to do anything to address the additional memory. 设置为AnyCPU的.NET应用程序将自动成为x64上的64位应用程序,因此您无需执行任何操作来解决附加内存问题。

Keep in mind, however, that the CLR imposes a 2 GB limit on any single object, so while your application may use a lot of memory, you cannot create a 2 TB array for instance. 但请记住,CLR对任何单个对象施加了2 GB的限制,因此虽然您的应用程序可能会占用大量内存,但您无法创建2 TB阵列。 More info in this question: Single objects still limited to 2 GB in size in CLR 4.0? 此问题中的更多信息: CLR 4.0中单个对象的大小仍限制为2 GB?

The maximum memory limit for x64 processes is 8 TB, but the practical limit is far less as it depend on the amount of physical memory and the pagefile size on your system. x64进程的最大内存限制为8 TB,但实际限制要小得多,因为它取决于系统上的物理内存量和页面文件大小。 See this post for more details on this. 有关详细信息,请参阅此帖子

The IMAGE_FILE_LARGE_ADDRESS_AWARE affect an x86 process running on a x64 OS (or a x86 OS with the /3GB directive). IMAGE_FILE_LARGE_ADDRESS_AWARE影响在x64 OS(或带有/ 3GB指令的x86 OS)上运行的x86进程。 Your x64 application does not need to set the large address aware flag and it will be able to use all the available virtual memory on your system. 您的x64应用程序不需要设置大地址识别标志,它将能够使用系统上所有可用的虚拟内存。

实际上,该文章声明您可以访问8 TB的虚拟地址空间(是的,这是真的)。

Actually on an x64 OS if your application is compiled for AnyCPU then you don't need to do anything special. 实际上在x64操作系统上,如果你的应用程序是为AnyCPU编译的,那么你不需要做任何特别的事情。 The JIT will create an x64 image at runtime or an x86 image when run on a 32 bit system. JIT将在运行时创建x64映像,或者在32位系统上运行时创建x86映像。

Moving to a 64 bit definitely helps cut out the OutOfMemoryExceptions, but you might want to focus on your system architecture and coding mechanisms to avoid these as it would only be a matter of time before they surface on the 64 bit machine as well. 移动到64位肯定有助于删除OutOfMemoryExceptions,但您可能希望专注于您的系统架构和编码机制以避免这些,因为它们在64位机器上也只是时间问题。
One more advantage of moving to 64 bit machines is that with an 8 TB of virtual address space, Garbage collection for .NET happens infrequently. 迁移到64位计算机的另一个优点是,对于8 TB的虚拟地址空间,.NET的垃圾收集很少发生。 This does improve application performance by increasing the available virtual space for your program. 这确实通过增加程序的可用虚拟空间来提高应用程序性能。

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

相关问题 CLR /从32位进程切换到64位进程后的高内存消耗 - CLR / High memory consumption after switching from 32-bit process to 64-bit process c#从64位进程调用LoadLibrary加载64位库失败 - c# calling LoadLibrary from a 64-bit process to load a 64-bit library fails 无论32位还是64位,如何杀死进程? - How to kill process regardless whether it's 32 or 64-bit? 如何在64位.NET进程中设置MinWorkingSet和MaxWorkingSet? - How to set MinWorkingSet and MaxWorkingSet in a 64-bit .NET process? 从 64 位进程加载 .net 1.1 程序集 - Loading .net 1.1 assembly from 64-bit process 为什么OleDbConnection在64位进程上引发InvalidOperationException而在32位进程上引发OleDbException - Why OleDbConnection throws InvalidOperationException on 64-bit process and OleDbException on 32-bit process 使用WMI,如何确定远程进程是32位还是64位? - Using WMI, how can I determine whether a remote process is 32-bit or 64-bit? 在64位环境中将指定的NUnit测试作为32位进程运行 - Run a specified NUnit test as a 32-bit process in a 64-bit environment 如何以编程方式确定特定进程是 32 位还是 64 位 - How to determine programmatically whether a particular process is 32-bit or 64-bit 从 32 位 Windows 服务使用 64 位进程外 COM DLL - Using 64-bit out of process COM DLL from 32-bit Windows Serivce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM