是否有可能完全避免堆碎片? [英] Is it possible to completely avoid heap fragmentation?

查看:202
本文介绍了是否有可能完全避免堆碎片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果动态内存的解除分配总是以与分配相反的方向进行。在这种情况下,是否保证堆不会变成碎片?

For example, if deallocations of dynamic memory are always done in opposite direction to allocations. In that case, is it guaranteed that heap will not become fragmented?

从理论的角度来看:对于一个非平凡的应用程序来说,存在一些现实的方法来管理内存完全避免堆碎片? (堆中的每个原子变化之后,堆是否仍然未分段?)

And from theoretical point of view: Does there exist some realistic way for a nontrivial application to manage memory to completely avoid heap fragmentation? (After each atomic change in heap, is heap still unfragmented?)

推荐答案


对于非平凡应用程序如何管理内存以完全避免堆碎片

Exist some realistical way for nontrivial application how to manage memory to completely avoid heap fragmentation

是的。分配堆栈上的一切。

Yes. Allocate everything on the stack. This may seem like a counsel of perfection but I've done it in non-trivial programs.

编辑为了绝对的清晰和避免疑义,我们已经完成了这项工作。 ,我说'堆栈'。我清楚地意味着自动存储,即局部变量堆栈,而不是任何堆栈类。关于这一点的一些评论基本上是钝的。

EDIT For absolute clarity and avoidance of doubt, I said 'the stack'. By that I clearly mean automatic storage, i.e. the local variable stack, not any stack class. Some of the comments about this are basically obtuse.

这篇关于是否有可能完全避免堆碎片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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