简体   繁体   English

如何获得分配给每一代(Gen0,Gen1,Gen2)的堆内存?

[英]How to get the heap memory allocated to each generation (Gen0,Gen1,Gen2)?

As stated in CLR via C#, "When CLR initializes, it selects a budget size for each generation.". 如CLR通过C#所述:“ CLR初始化时,它将为每一代选择预算大小。” It assumes 256KB for Gen0, 2MB for Gen1, 10MB for Gen2.(not sure if this includes Large Object Heap) Gen0假定为256KB,Gen1假定为2MB,Gen2假定为10MB(不确定是否包括大对象堆)。

This budget must, ofcourse, be getting increased as more objects are created and as the size of the heap increases. 当然,随着创建更多的对象以及增加堆的大小,该预算必须增加。

I know about GC.GetTotalMemory() method which returns the total memory that has been consumed, but it gives no information about per generation consumption. 我知道GC.GetTotalMemory()方法,该方法返回已消耗的总内存,但没有提供有关每代消耗的信息。

Is there a way to get the heap size allocated to each generation? 有没有一种方法可以将堆大小分配给每一代?

IF you really want to dig deeper into .NET memory management then I recommend checking these links out: 如果您真的想更深入地研究.NET内存管理,那么建议您检查以下链接:

The above links provide lots of insight AND a CLR memory profiler written by MS which comes with full source code... 上面的链接提供了很多见识,以及由MS编写的CLR内存分析器,它带有完整的源代码...

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM