当解决托管堆碎片 [英] When to address managed heap fragmentation

查看:190
本文介绍了当解决托管堆碎片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读一本<一个href="http://joshsmithonwpf.word$p$pss.com/2007/08/29/a-base-class-which-implements-inotifypropertychanged/"相对=nofollow>博客条目由约什 - 史密斯,他使用了缓存机制,以降低托管堆碎片的。他的缓存减少在稍慢的执行速度的成本正在创建短命的对象的数量。

如何的问题多少是托管堆碎片像C#中的托管语言?你如何诊断,如果这是一个问题?在什么情况下你会通常需要处理呢?

解决方案
  

不要太快。这通常是非常便宜的有短暂的对象。对于一个高速缓存是有利可图的存在将不得不(很)多candiadates,他们应该活足够长的时间,使其下一代。

  您

如何诊断,如果这是一个问题?

通过探查。我不太确定这篇文章的作者这样做。

  

如何的问题多少是托管堆碎片像C#中的托管语言?

据我所知,这是罕见的。 NET有一个压缩垃圾收集器,即prevents大多数形式的碎片。没有与大对象问题,堆的时候。


编辑:

当你通过下面的文章的评论,你会发现有人测量了一下,发现缓存比每次创建新的EventArgs慢了许多。

结论:测量,然后再开始优化。这不是一个好主意/例子。

I was reading a blog entry by Josh Smith where he used a cache mechanism in order to "reduce managed heap fragmentation". His caching reduces the number of short-lived objects being created at the cost of slightly slower execution speed.

How much of a problem is managed heap fragmentation in a managed language like C#? How can you diagnose if it's an issue? In what situations would you typically need to address it?

解决方案

When

Not too quickly. It is generally very cheap to have short lived objects. For a cache to be profitable there would have to be (very) many candiadates and they should live long enough to make it to the next generation.

How can you diagnose if it's an issue?

With a Profiler. I'm not so sure the author of the article did that.

How much of a problem is managed heap fragmentation in a managed language like C#?

As far as I know it is rare. .NET has a compacting Garbage collector, that prevents most forms of fragmentation. There are issues with the Large Object Heap sometimes.


Edit:

When you go through the comments below the article you will find that someone measured it and found the cache to be a lot slower than creating new eventargs each time.

Conclusion: Measure before you start optimizing. This was not a good idea/example.

这篇关于当解决托管堆碎片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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