内存碎片C ++ [英] Memory fragmentation C++

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

问题描述

嗨!



我和我的一些好朋友决定尝试在C ++中制作一个小游戏,只是为了好玩,在DirectX和其他一些原创图书馆的帮助下用C ++编写。我想说我们所有人都有早期开发项目的经验,但几乎只有托管语言。我以前一直用C ++编程,但从来没有更大的项目或解决方案。



当我们进行一些研究时,我们发现似乎有很多人担心在频繁创建小型短期对象或内存使用量增长时,堆上的内存碎片。我们有点担心在设计游戏引擎时我们可能不得不考虑这个问题,而不是仅仅使用新创建C#或Java方式的对象。 (我知道你必须释放内存,这与你提到的托管语言不同)



这是你应该担心的事情,如果有的话我们有什么选择?我已经阅读了一些关于内存池的内容,但我们是否需要一个内存池,是否有任何已知的工作我们可以使用,如果是的话?我们非常感谢所有反馈。



最好的问候

WaZoX

Hi!

I and some good friends of mine decided to try making a smaller game in C++ just for fun, with help of DirectX and some other libraries original written in C++. I would say all of us have experience from earlier development projects but however almost only from managed languages. I have been programming in C++ before but never any bigger projects or solutions.

When we did a bit of research we found that it seems like a lot of people worries about memory fragmentation on the heap when creating small short lived objects frequently or when the memory usage grows. We got a bit concerned that we may have to take this under consideration when designing the game engine, instead of just creating objects the C# or Java way with "new". (I''m aware of that you must free the memory unlike in the managed languages mentioned)

Is this something you should worry about and if so what are our options? I have read a bit about memory pools, but will we need one and is there any known already working we could use if so? We are very thankful for all feedback we get on this.

Best Regards
WaZoX

推荐答案

我和我的一些好朋友决定尝试用C ++制作一个小游戏,只是为了好玩很棒:-D



很多人担心内存碎片

很多人花时间担心最终会出现问题的事情...



这是你应该担心的事情吗?

可能不是,但创建相同/类似大小的对象池可以提高程序的性能 - 这可能是使用内存池而不是碎片的更好理由。



C#或带有new的Java方式。请记住删除这些对象,或者看看std :: make_shared<> ; &安培; std :: shared_ptr<>



问候

Espen Harlinn
I and some good friends of mine decided to try making a smaller game in C++ just for fun Great :-D

a lot of people worries about memory fragmentation
Many spend time worrying on things that eventually turn out not to be a problem ...

Is this something you should worry about
Probably not, but creating pools of same/similar sized objects can enhance the performance of your program - that''s probably a better reason for using memory pools than fragmentation.

C# or Java way with "new". Just remember to delete those objects, or take a look at std::make_shared<> & std::shared_ptr<>

Regards
Espen Harlinn


一个不错的顿悟关于高级内存管理:):

16使用
A nice "epiphany" about advanced memory management :) :
16 used from


0.01 [ ^ ]


这篇关于内存碎片C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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