auto_ptr内存泄漏与数组? [英] auto_ptr memory leak with arrays?

查看:80
本文介绍了auto_ptr内存泄漏与数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 http:/ /www.kuro5hin.org/story/2005/10/31/53857/831

auto_ptr使用" delete"在它的析构函数而不是delete []。

文章是最新的,所以我想知道这对于任何托管实现是否一般都是真的



Hi, I was reading on http://www.kuro5hin.org/story/2005/10/31/53857/831
that auto_ptr uses "delete" in its destructor instead of delete[]. The
article is fairly recent, so I was wondering if this is true in general
for any hosted implementation.

推荐答案

" Shark" < CP ******* @ yahoo.com>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...
"Shark" <cp*******@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
我正在阅读 http: //www.kuro5hin.org/story/2005/10/31/53857/831
auto_ptr使用" delete"在它的析构函数而不是delete []。
文章是最新的,所以我想知道这对于任何托管实现是否都是正确的。
Hi, I was reading on http://www.kuro5hin.org/story/2005/10/31/53857/831
that auto_ptr uses "delete" in its destructor instead of delete[]. The
article is fairly recent, so I was wondering if this is true in general
for any hosted implementation.




是的,这是真的,我也遇到过这个问题,所以我最初复制了

并粘贴了一个auto_ptr实现并更改了一行删除[]。


但是现在我使用了boost ,我认为这是一个好主意。看看boost smart

指针,如boost :: scoped_array。


Andrew



Yes this is true, I also encountered this problem, so I originally copied
and pasted a auto_ptr implementation and change the one line to delete[].

But now I use boost, which I think a far better idea. Look at boost smart
pointers such as boost::scoped_array.

Andrew


文章< 11 ********************** @ g49g2000cwa.googlegroups .com>,

" Shark" < CP ******* @ yahoo.com>写道:
In article <11**********************@g49g2000cwa.googlegroups .com>,
"Shark" <cp*******@yahoo.com> wrote:
我正在阅读 http://www.kuro5hin.org/story/2005/10/31/53857/831
auto_ptr使用删除在它的析构函数而不是delete []。
文章是最新的,所以我想知道这对于任何托管实现是否都是正确的。
Hi, I was reading on http://www.kuro5hin.org/story/2005/10/31/53857/831
that auto_ptr uses "delete" in its destructor instead of delete[]. The
article is fairly recent, so I was wondering if this is true in general
for any hosted implementation.




只需使用向量。


-

魔术取决于传统和信仰。它不欢迎观察,

也不会通过实验获利。另一方面,科学的经验基于
;它可以通过观察和实验来纠正。



Just use a vector.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.


Shark写道:
我正在阅读 http://www.kuro5hin.org/story/2005/10/31/53857/ 831
auto_ptr使用删除在它的析构函数而不是delete []。
文章是最新的,所以我想知道这对于任何托管实现是否都是正确的。
Hi, I was reading on http://www.kuro5hin.org/story/2005/10/31/53857/831
that auto_ptr uses "delete" in its destructor instead of delete[]. The
article is fairly recent, so I was wondering if this is true in general
for any hosted implementation.




如果你需要一个数组,那么你不应该使用auto_ptr,并且

而是使用std :: vector。

auto_ptr表示单个对象,std :: vector表示

多个对象。



If you need an array, then you should not be using auto_ptr, and
instead use std::vector.

auto_ptr represents a single object, and std::vector represents
multiple objects.


这篇关于auto_ptr内存泄漏与数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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