删除如何工作? [英] How does delete work?

查看:112
本文介绍了删除如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

C编程:免费如何知道多少免费?

如何删除知道它需要释放多少字节?
我读到在由包含块地址细节的new返回的实际指针地址之前有一些块。

How does delete know how many bytes it has to free? I read that there is some block before the actual pointer address that is returned by new which contains block address details.

这里有谁知道这个块有多少字节,或者块的格式如何?

Anyone here who knows how many bytes this block has or how the format of that block is?

推荐答案

一般来说,这是实现相关的。

In general, this is implementation-dependent.

通常实现的方式是new / malloc将分配比你所要求的稍多的字节,并且会使用额外的字节来保存一些书:所分配的块也将保持在链表中,因此额外的字节将用于存储next / prev指针以及块的大小。

The way this is usually implemented is that new/malloc will allocate slightly more bytes than you asked for, and will use the extra bytes for some book-keeping: many times the allocated blocks will also be maintained in a linked-list, and so the extra bytes will be used to store the next/prev pointer, as well as the size of the block.

但是,这不是强制性的。

This is not mandatory, however. The new/malloc calls can just as well store your pointer and the block's size in, say, a map.

如果你对一个特定的实现感兴趣,你可以使用一个新的/ malloc调用来存储你的指针和块的大小。必须提供更多的信息(例如,你使用什么运行时/编译器?)。

If you're interested in a specific implementation, you will have to provide more information (e.g. what runtime/compiler are you using?).

这篇关于删除如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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