简体   繁体   English

这句话是什么意思?

[英]What does this statement mean?

When reading the Improving .NET Application Performance and Scalability I have bumped into this under "Improving Managed Code Performance/Garbage Collector Guidlines: 在阅读提高.NET应用程序性能和可伸缩性时,我在“改进托管代码性能/垃圾收集器指南”中遇到了这个问题:

Avoid preallocating and chunking memory.

But the book never goes into explaining as to why preallocating is bad or what the Chunking really means in light of GC optimization. 但本书从未解释过为什么预分配是坏的或者Chunking在GC优化方面的真正含义。

Can someobody shed more light on the issue and explain to me why the 2 are bad and what do they really mean in terms of using GC with .net? 有人可以对这个问题有更多的了解,并向我解释为什么这两个是坏的,它们在使用GC的.net方面有什么意义?

http://www.microsoft.com/downloads/en/details.aspx?FamilyId=8A2E454D-F30E-4E72-B531-75384A0F1C47&displaylang=en http://www.microsoft.com/downloads/en/details.aspx?FamilyId=8A2E454D-F30E-4E72-B531-75384A0F1C47&displaylang=en

Pre-allocating memory is a technique that doesn't scale well. 预分配内存是一种不能很好地扩展的技术。 Chunking may push the allocation in the Large Object Heap. 分块可以推动大对象堆中的分配。 Either will make you use memory needlessly. 要么会让你不必要地使用内存。 Trust the garbage collector, allocate when you need it. 信任垃圾收集器,在需要时进行分配。

It does have a few things to say about what the problems are. 关于问题是什么,它确实有一些说法。 Page 198: 页面198:

C++ programmers often allocate a large block of memory (using malloc) and then use chunks at a time, to save multiple calls to malloc. C ++程序员经常分配一大块内存(使用malloc),然后一次使用块,以保存对malloc的多个调用。 This is not advisable for managed code for several reasons: 由于以下几个原因,这不适用于托管代码:

  • Allocation of managed memory is a quick operation and the garbage collector has been optimized for extremely fast allocations. 托管内存的分配是一种快速操作,垃圾收集器已针对极快的分配进行了优化。 The main reason for preallocating memory in unmanaged code is to speed up the allocation process. 在非托管代码中预分配内存的主要原因是加快分配过程。 This is not an issue for managed code. 对于托管代码,这不是问题。
  • If you preallocate memory, you cause more allocations than needed; 如果预分配内存,则会导致分配超出所需的分配; this can trigger unnecessary garbage collections. 这可以触发不必要的垃圾收集。
  • The garbage collector is unable to reclaim the memory that you manually recycle. 垃圾收集器无法回收您手动回收的内存。
  • Preallocated memory ages and costs more to recycle when it is ultimately released. 预分配的内存时间和最终发布后的回收成本更高。

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

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