删除&新的c ++ [英] delete & new in c++

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

问题描述

这可能是非常简单的问题,但请帮助我。

This may be very simple question,But please help me.

我想知道当我打电话新&删除,例如在下面的代码

i wanted to know what exactly happens when i call new & delete , For example in below code

char * ptr=new char [10];

delete [] ptr;

调用新的返回内存地址。它在堆上分配精确的10个字节,其中关于大小的信息被存储。当我调用删除相同的指针,我在调试器中看到有很多字节在10字节之前和之后更改。

call to new returns me memory address. Does it allocate exact 10 bytes on heap, Where information about size is stored.When i call delete on same pointer,i see in debugger that there are a lot of byte get changed before and after the 10 Bytes.

每个新的包含新分配的字节数信息的标头。

Is there any header for each new which contain information about number of byte allocated by new.

非常感谢

推荐答案


分配精确的10个字节

Do it allocate exact 10 bytes

这是实现相关的。保证是至少 10个字符。

That's implementation dependant. The guarantee is "at least 10 chars".



Where information about size is stored?

这是实现相关的。


每个新的包含新的分配的字节数的信息?

Is there any header for each new which contain information about number of byte allocated by new?

这是实现相关的。

这是实现依赖我的意思是它没有在标准中定义。

By "that's implementation dependant" I mean it's not defined in the standard.

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

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