C#和.NET垃圾收集器的性能 [英] C# and .Net Garbage collector performance

查看:101
本文介绍了C#和.NET垃圾收集器的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在C#和.NET一个游戏,我正打算实施更新在游戏世界中的游戏对象的消息。这些消息是C#的参考对象。

I am trying to make a game in C# and .NET, and I was planning to implement messages that update the game objects in the game world. These messages would be C# reference objects.

我想这种做法,因为做这种方式会更容易通过网络发送给他们,如果我希望游戏是多人。

I want this approach because doing it this way would be easier to send them over a network if I want the game to be multiplayer.

但是,如果我有很多的消息,会不会是垃圾收集相当紧张?并不会影响到游戏?消息类本身与4或5人相当少至多。

But if I have a lot of messages, won't it be quite stressful for the garbage collector? And won't that affect gameplay? The message classes themselves are quite small with 4 or 5 members at most.

这些消息将生成一对夫妇每秒钟在游戏世界中的每个对象。

These messages will be generated a couple of times per second for each object in the game world.

推荐答案

在以后的版本GC的,但更准确地说4.5,异步运行的代平0和1这高度降低了GC的影响。

The GC in later versions, but more precisely 4.5, runs asynchronously for generations level 0 and 1. This has highly reduced the impact of GC.

如果你的对象是短命的,他们不应该代平0的大部分时间通过。 0级是最快的一代GC的清理。

If your objects are short-lived they should not pass from generation level 0 most of the time. Level 0 is the fastest generation to clean up by the GC.

底线,我不会考虑过早优化我的代码生怕GC性能。

Bottom line, I would not consider prematurely optimizing my code for fear of GC performance.

过早的优化是所有罪恶通过
的根的 DonaldKnuth

就个人而言,我建议这个的文章有了更深的了解。

Personally, i'd recommend this article for a deeper understanding

这篇关于C#和.NET垃圾收集器的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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