对C ++中动态分配的内存进行碎片整理 [英] Defragmentation of dynamically allocated memory in C++

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

问题描述

如何在C ++中对动态分配的内存(使用new和malloc运算符分配)进行碎片整理?

How does the defragmentation of dynamically allocated memory (allocated using the new and malloc operator ) work in C++?

推荐答案

C ++堆中没有碎片整理,因为应用程序可以自由保留指向已分配内存的指针.因此,堆管理器无法移动已分配的内存.唯一可能的碎片整理"是如果您释放两个相邻的块.然后,堆管理器会将这两个块合并为一个更大的空闲块,可再次用于分配.

There is no defragmentation in the C++ heap because the application is free to keep pointers to allocated memory. Thus the heap manager cannot move memory around that is already allocated. The only "defragmentation" possible is if you free two adjacent blocks. Then the heap manager will combine the two blocks to a single larger free block that can be used for allocation again.

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

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