删除POD数组 - 在哪些平台上不起作用? [英] delete POD array - on which platforms does it not work?

查看:47
本文介绍了删除POD数组 - 在哪些平台上不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


char * p = new char [n]; // POD!

....

delete [] p; // std compliance

delete p; //将在VC8上工作

free(p); //也适用于VC8

我对哪两个平台/编译器感兴趣,后两个语句

不起作用。 (访问违规或内存泄漏)。


谢谢!

br,

Martin

Hi all!

char* p = new char[n]; // POD!
....
delete[] p; // std compliant
delete p; // will work on VC8
free(p); // will also work on VC8
I am interested on which platforms/compilers the second two statements
would not work. (access violation or mem-leak).

thanks!
br,
Martin

推荐答案

Martin T.写道,On 2.4.2008 7:30:
Martin T. wrote, On 2.4.2008 7:30:

大家好!


char * p = new char [n]; // POD!

...

delete [] p; // std compliance

delete p; //将在VC8上工作

free(p); //也适用于VC8


我对哪两个平台/编译器感兴趣,后两个语句

不起作用。 (访问违规或内存泄漏)。
Hi all!

char* p = new char[n]; // POD!
...
delete[] p; // std compliant
delete p; // will work on VC8
free(p); // will also work on VC8
I am interested on which platforms/compilers the second two statements
would not work. (access violation or mem-leak).



为什么重要?即使它编译和工作也是错误的C ++。


-

VH

Why does it matter? It is wrong C++ even if it compiles and works.

--
VH


On 2 huhti,08:30,Martin T. < 0xCDCDC ... @ gmx.atwrote:
On 2 huhti, 08:30, "Martin T." <0xCDCDC...@gmx.atwrote:

delete p; //将在VC8上工作

free(p); //也适用于VC8
delete p; // will work on VC8
free(p); // will also work on VC8



你确定这些不会搞砸VC8中的任何东西吗?

无论如何这个问题是脑死。您对数组使用delete []

,而对new new使用free()。​​

Are you sure these don''t mess up anything in VC8?
Anyway this question is braindead. You use delete[]
for arrays and never free() with operator new.


Krice写道:
Krice wrote:

On 2 huhti,08:30,Martin T. < 0xCDCDC ... @ gmx.atwrote:
On 2 huhti, 08:30, "Martin T." <0xCDCDC...@gmx.atwrote:

> delete p; //将在VC8上工作
free(p); //也适用于VC8
>delete p; // will work on VC8
free(p); // will also work on VC8



你确定这些不会搞砸VC8中的任何东西吗?


Are you sure these don''t mess up anything in VC8?



是的,100%肯定。

Yes, 100% sure.


无论如何,这个问题是脑死亡。对数组使用delete []

,而对new new使用free()。
Anyway this question is braindead. You use delete[]
for arrays and never free() with operator new.



这个问题非常有效。事实上它变得更有效了

这样的答案。我还可以改写它:

它(只)*真的*邪恶,或者有没有人知道它会为POD打破
的平台?


br,

Martin

This is question is quite valid. Indeed it becomes more valid with
answers such as this. I could also rephrase it:
Is it (just) *really* evil, or does anyone know of a platform where it
will break for PODs?

br,
Martin


这篇关于删除POD数组 - 在哪些平台上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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