VirtualMemorySize64和PrivateMemorySize64有什么区别 [英] What is the difference between VirtualMemorySize64 and PrivateMemorySize64

查看:257
本文介绍了VirtualMemorySize64和PrivateMemorySize64有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不了解 Process.PrivateMemorySize64 Process.VirtualMemorySize64

我创建了一个简单的控制台应用程序,该应用程序将10倍10兆字节分配给一个字节数组。

I have created a simple console application which allocates 10 times 10 megabyte into an byte array.

const int tenMegabyte = 1024*1024*10;
long allocatedMemory = 0;
List<byte[]> memory = new List<byte[]>();
for (int i = 0; i < 10; i++)
{
    allocatedMemory += tenMegabyte;
    Console.WriteLine("Allocated memory:    " + PrettifyByte(allocatedMemory));
    Console.WriteLine("VirtualMemorySize64: " + PrettifyByte(Process.GetCurrentProcess().VirtualMemorySize64));
    Console.WriteLine("PrivateMemorySize64: " + PrettifyByte(Process.GetCurrentProcess().PrivateMemorySize64));
    Console.WriteLine();
    memory.Add(new byte[tenMegabyte]);
}

PrivateMemorySize64的工作与我期望的一样:它以一定的大小开头,并且随着分配的内存增长。

The PrivateMemorySize64 works as i did expect: It starts with a certain size, and grows with the allocated memory.

但是VirtualMemorySize64似乎从一开始就分配了很多内存,甚至对于控制台应用程序(32位为180mb,64位为560mb)

But the VirtualMemorySize64 seems to allocate a lot of memory at the very start even for a console application (180mb for 32bit and 560mb for 64bit)


问题:


  • VirtualMemorySize的PrivateMemorySize部分吗?
    如果为真,则其余VirtualMemorySize是什么?它只是保留的内存,还是实际上在ram / page文件中?

  • 为什么即使一个简单的控制台应用程序也会分配超过500mb的VirtualMemory?

  • 如果我的应用程序使用1GB的PrivateMemorySize和20GB的VirtualMemorySize,我应该关心还是可以忽略它?

  • 为什么64位版本的程序分配了那么多的VirtualMemory?
  • >
  • Is the PrivateMemorySize part of the VirtualMemorySize? If this is true, what is the rest of the VirtualMemorySize? Is it just reserved memory, or is this actually in ram/page file?
  • Why does even a simple console application allocate more than 500mb VirtualMemory?
  • If my application use 1GB of PrivateMemorySize and 20GB of VirtualMemorySize, should i care or can this be ignored?
  • Why does the 64bit version of the program allocate so much more VirtualMemory?

推荐答案

VirtualMemorySize测量您的进程使用的虚拟内存的 all 。其中包括计算机上所有其他进程共享的页面。在.NET程序中,它包括操作系统,CLR,抖动和ngen-ed Framework程序集。

VirtualMemorySize measures all of the virtual memory that your process uses. Which includes the pages shared by all other processes on your machine. Which in a .NET program includes the operating system, CLR, jitter and the ngen-ed Framework assemblies.

PrivateMemorySize度量专用于您的进程的虚拟内存,不能用于由其他进程共享。在.NET程序中,哪一个包含所有数据以及未进行ngen编码的任何伪代码。

PrivateMemorySize measures the virtual memory that's dedicated to your process and cannot be shared by other processes. Which in a .NET program includes all the data and any jitted code that isn't ngen-ed.

两者都是虚拟内存测量值,在内部仅表示为处理器。每4096字节内存一个。实际RAM使用量是一个非常不同的数字,由Process.WorkingSet表示。通常它没有什么用,但是当其他进程需要RAM且您需要使用的某些应用需要映射时,它会迅速变化。您的操作系统和.NET都经过了优化,以使用大量VM,现代机器上有很多可用的VM,它胜过了替代磁盘。

Both are virtual memory measurements, internally represented as just numbers to the processor. One each for every 4096 bytes of memory. Actual RAM usage is a very different number, represented by Process.WorkingSet. Not generally useful, it can change very rapidly when other processes require RAM and some of what you use needs to be mapped out. Both your operating system and .NET were optimized to use lots of VM, there is a lot of it available on modern machines and it beats the alternative, the disk.


VirtualMemorySize的PrivateMemorySize部分吗?如果是这样,其余的VirtualMemorySize是什么?是只是保留的内存,还是在ram / page文件中?

Is the PrivateMemorySize part of the VirtualMemorySize? If this is true, what is the rest of the VirtualMemorySize? Is it just reserved memory, or is this actually in ram/page file?

是的。如第一段所述,其余为共享内存

Yes. The rest is shared memory as noted in the first paragraph


为什么即使一个简单的控制台应用程序也分配超过500mb的VirtualMemory?

Why does even a simple console application allocate more than 500mb VirtualMemory?

操作系统和.NET运行时都不只是控制台应用程序很小的一部分,仍然都需要执行它们。由于所有进程都共享它们,因此您不必太在意。您也无能为力。除非分配大量内存,否则大型控制台应用程序通常不会添加更多的VM。

Neither the operating system nor the .NET runtime is partial to your console app being small, both are still needed to execute it. Since they are shared by all processes, you don't care that much about it. Nor is there anything you can do about it. A "big" console app doesn't usually add that much more VM unless it allocates a lot of memory.


如果我的应用程序使用1GB

If my application use 1GB of PrivateMemorySize and 20GB of VirtualMemorySize, should i care or can this be ignored?

1GB的私有内存没什么好担心的? 。 20GB的VM过多。 GC堆的大小是值得关注的大小,当它必须翻遍数GB的堆时,收集会变慢。

1GB of private memory isn't much to worry about. 20GB of VM is getting excessive. The size of the GC heap is the one to watch, collections can get slow when it has to plow through multiple gigabytes of heap.


程序的64位版本会分配更多的VirtualMemory吗?

Why does the 64bit version of the program allocate so much more VirtualMemory?

嗯,64是2 *32。这不太可扩展像这样,64位进程仍然倾向于使用大量的 ints 。编写一个现代的64位操作系统是为了假设有足够的硬件资源可用,Win8确实需要8 GB的RAM才能正常工作。

Well, 64 is 2 * 32. That doesn't quite scale like that, a 64-bit process still tends to use plenty of ints. A modern 64-bit OS was written to assume plenty of hardware resources to be available, Win8 does require 8 GB of RAM to work smoothly.

这篇关于VirtualMemorySize64和PrivateMemorySize64有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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