delete and delete[]
-
No, this isn't a programming question. I seem to recall that on some version of VC++, delete and delete[] do the same thing, am I right in thinking that ? If so, does anyone have an online reference to the fact ? Note: I NEVER use delete without the [] to delete an array, but I thought that proper form didn't make a difference, is all. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
delete
? [digs into memory] Oooooh - that thing you used to have to do way back in the olden days when memory management was a problem. Right. ;P OK - I admit. I missdelete
. I really do cheers, Chris Maunder -
delete
? [digs into memory] Oooooh - that thing you used to have to do way back in the olden days when memory management was a problem. Right. ;P OK - I admit. I missdelete
. I really do cheers, Chris MaunderROTFL - very good. Actually, I'm torn between liking how much easier C# is, and the feeling that I'm becoming less skilled because I don't have to work as hard as I used to, as a matter of course. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
No, this isn't a programming question. I seem to recall that on some version of VC++, delete and delete[] do the same thing, am I right in thinking that ? If so, does anyone have an online reference to the fact ? Note: I NEVER use delete without the [] to delete an array, but I thought that proper form didn't make a difference, is all. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
Christian Graus wrote: I seem to recall that on some version of VC++, delete and delete[] do the same thing, am I right in thinking that ? As far as I remember, that was true only for primitive types (without destructors).
-
No, this isn't a programming question. I seem to recall that on some version of VC++, delete and delete[] do the same thing, am I right in thinking that ? If so, does anyone have an online reference to the fact ? Note: I NEVER use delete without the [] to delete an array, but I thought that proper form didn't make a difference, is all. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
The problem is that if you "mix and match", the destructor is only called for the first object in the array. ie
LPBYTE pData = new CObject[10]; delete pData; // only the destructor for first allocated CObject is called
butdelete [] pData; // all 10 destructors are called, one for each allocated CObject
(Graham clicks Submit, dashes off to put on flame-proof clothing for encouraging programming questions in the Lounge, and hides under the desk, quivering nervously) -
delete
? [digs into memory] Oooooh - that thing you used to have to do way back in the olden days when memory management was a problem. Right. ;P OK - I admit. I missdelete
. I really do cheers, Chris MaunderChris Maunder wrote: the olden days when memory management was a problem. You mean before STL and smart pointers, right? ;)
-
Christian Graus wrote: I seem to recall that on some version of VC++, delete and delete[] do the same thing, am I right in thinking that ? As far as I remember, that was true only for primitive types (without destructors).
The type in question is a char *, so it would stand. Do you have any references ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
delete
? [digs into memory] Oooooh - that thing you used to have to do way back in the olden days when memory management was a problem. Right. ;P OK - I admit. I missdelete
. I really do cheers, Chris MaunderYou don't use it in VB or VBScript so you can go back to sleep ;P Cheers, Tom Archer "Use what talents you possess. The woods would be very silent if no birds sang there except those that sang best." - William Blake * Inside C# -Second Edition * Visual C++.NET Bible * Extending MFC Applications with the .NET Framework
-
The type in question is a char *, so it would stand. Do you have any references ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
Christian Graus wrote: Do you have any references ? Nope. Don't quote me on this, I just *think* I remember this being true.
-
ROTFL - very good. Actually, I'm torn between liking how much easier C# is, and the feeling that I'm becoming less skilled because I don't have to work as hard as I used to, as a matter of course. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
I kind of get that feeling too from time to time, which is why I at least try to write a bit of unmanaged code from time to time, like my shell extensions for .NET assemblies here on CP - yeah, I know, it's still geared toward .NET. :sigh: What's weird is saying "unmanaged code". It used to just be "code". But then again, "organic produce" just used to be "produce", but now you have to pay extra for getting produce grown the way it was intended.
Microsoft MVP, Visual C# My Articles
-
I kind of get that feeling too from time to time, which is why I at least try to write a bit of unmanaged code from time to time, like my shell extensions for .NET assemblies here on CP - yeah, I know, it's still geared toward .NET. :sigh: What's weird is saying "unmanaged code". It used to just be "code". But then again, "organic produce" just used to be "produce", but now you have to pay extra for getting produce grown the way it was intended.
Microsoft MVP, Visual C# My Articles
I REFUSE to say unmanaged code. It's not unmanaged, it's SELF managed. Microsoft can get stuffed if they want to imply those things are the same. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
No, this isn't a programming question. I seem to recall that on some version of VC++, delete and delete[] do the same thing, am I right in thinking that ? If so, does anyone have an online reference to the fact ? Note: I NEVER use delete without the [] to delete an array, but I thought that proper form didn't make a difference, is all. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
There is an extensive explanation on the subject in September 1996 "C++ Q & A" by Paul DiLascia: http://www.microsoft.com/msj/archive/S202C.aspx[^] You have to scroll down a little bit to the chapter starting "I've been teaching myself C++"
/* I C++, therefore I am... */
-
No, this isn't a programming question. I seem to recall that on some version of VC++, delete and delete[] do the same thing, am I right in thinking that ? If so, does anyone have an online reference to the fact ? Note: I NEVER use delete without the [] to delete an array, but I thought that proper form didn't make a difference, is all. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
Christian Graus wrote: No, this isn't a programming question. Err, why not? It fits perfectly in the C++ forum. - Anders Money talks, but all mine ever says is "Goodbye!" ShotKeeper, my Photo Album / Organizer Application[^]
-
There is an extensive explanation on the subject in September 1996 "C++ Q & A" by Paul DiLascia: http://www.microsoft.com/msj/archive/S202C.aspx[^] You have to scroll down a little bit to the chapter starting "I've been teaching myself C++"
/* I C++, therefore I am... */
Thanks - that's just what I was looking for. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
Christian Graus wrote: No, this isn't a programming question. Err, why not? It fits perfectly in the C++ forum. - Anders Money talks, but all mine ever says is "Goodbye!" ShotKeeper, my Photo Album / Organizer Application[^]
Anders Molin wrote: Christian Graus wrote: No, this isn't a programming question. Err, why not? It fits perfectly in the C++ forum. I think this is part of a disease I call... Paradoxal Prefaceitious! Ever notice how people will preface their statements with contradictions in order that society, for whatever reason, will be more accepting of the later half of their statement? Here are the classic lines I love hearing: "No offense, but..." - followed by a completely offensive remark. "I don't mean to sound racist, but..." - followed by a remark that would make the KKK proud. The classic radio talk show caller statement: "I know you've got alot of callers waiting, so I'll be brief" - followed by 15 minutes of non-stop yapping that puts Foghorn Leghorn to shame. How a question about delete vs delete[] isn't considered a programming question is beyond me. The art of paradoxal prefaceitious has amazing powers, doesn't it?
"You will be killed by a poisoned fortune cookie." - Old fortune cookie proverb
-
Anders Molin wrote: Christian Graus wrote: No, this isn't a programming question. Err, why not? It fits perfectly in the C++ forum. I think this is part of a disease I call... Paradoxal Prefaceitious! Ever notice how people will preface their statements with contradictions in order that society, for whatever reason, will be more accepting of the later half of their statement? Here are the classic lines I love hearing: "No offense, but..." - followed by a completely offensive remark. "I don't mean to sound racist, but..." - followed by a remark that would make the KKK proud. The classic radio talk show caller statement: "I know you've got alot of callers waiting, so I'll be brief" - followed by 15 minutes of non-stop yapping that puts Foghorn Leghorn to shame. How a question about delete vs delete[] isn't considered a programming question is beyond me. The art of paradoxal prefaceitious has amazing powers, doesn't it?
"You will be killed by a poisoned fortune cookie." - Old fortune cookie proverb
Jack Rabbit wrote: Paradoxal Prefaceitious! Jack, you are a man of insight! ;) Maxwell Chen
-
Anders Molin wrote: Christian Graus wrote: No, this isn't a programming question. Err, why not? It fits perfectly in the C++ forum. I think this is part of a disease I call... Paradoxal Prefaceitious! Ever notice how people will preface their statements with contradictions in order that society, for whatever reason, will be more accepting of the later half of their statement? Here are the classic lines I love hearing: "No offense, but..." - followed by a completely offensive remark. "I don't mean to sound racist, but..." - followed by a remark that would make the KKK proud. The classic radio talk show caller statement: "I know you've got alot of callers waiting, so I'll be brief" - followed by 15 minutes of non-stop yapping that puts Foghorn Leghorn to shame. How a question about delete vs delete[] isn't considered a programming question is beyond me. The art of paradoxal prefaceitious has amazing powers, doesn't it?
"You will be killed by a poisoned fortune cookie." - Old fortune cookie proverb
:laugh::laugh::laugh: Thanks for the laugh! Shouldn't it really be paradoxal prefacitis?
itis
-itis \-i"tis\, [Gr. ?, orig, fem. adjective suffix.] A suffix used in medical terms
to denote an inflammatory disease of; as, arthritis; bronchitis, phrenitis.Funny stuff either way!
Paul Lyons, CCPL
Certified Code Project Lurker -
:laugh::laugh::laugh: Thanks for the laugh! Shouldn't it really be paradoxal prefacitis?
itis
-itis \-i"tis\, [Gr. ?, orig, fem. adjective suffix.] A suffix used in medical terms
to denote an inflammatory disease of; as, arthritis; bronchitis, phrenitis.Funny stuff either way!
Paul Lyons, CCPL
Certified Code Project LurkerPaul Lyons wrote: Shouldn't it really be paradoxal prefacitis? Nice one! :-D I am not a native English speaker. The previous spelling, prefaceitious, took me some time to look it up in dictionaries, but I don't find it. :doh: Maxwell Chen
-
:laugh::laugh::laugh: Thanks for the laugh! Shouldn't it really be paradoxal prefacitis?
itis
-itis \-i"tis\, [Gr. ?, orig, fem. adjective suffix.] A suffix used in medical terms
to denote an inflammatory disease of; as, arthritis; bronchitis, phrenitis.Funny stuff either way!
Paul Lyons, CCPL
Certified Code Project Lurker -
Anders Molin wrote: Christian Graus wrote: No, this isn't a programming question. Err, why not? It fits perfectly in the C++ forum. I think this is part of a disease I call... Paradoxal Prefaceitious! Ever notice how people will preface their statements with contradictions in order that society, for whatever reason, will be more accepting of the later half of their statement? Here are the classic lines I love hearing: "No offense, but..." - followed by a completely offensive remark. "I don't mean to sound racist, but..." - followed by a remark that would make the KKK proud. The classic radio talk show caller statement: "I know you've got alot of callers waiting, so I'll be brief" - followed by 15 minutes of non-stop yapping that puts Foghorn Leghorn to shame. How a question about delete vs delete[] isn't considered a programming question is beyond me. The art of paradoxal prefaceitious has amazing powers, doesn't it?
"You will be killed by a poisoned fortune cookie." - Old fortune cookie proverb
Yeah, and one more thing... When this is posted by someone like Christian Graus, no one minds, but if some newbie posted it, everyone would jump on him and tell him not to post that kinda crap in the lounge... Interesting eh? - Anders Money talks, but all mine ever says is "Goodbye!" ShotKeeper, my Photo Album / Organizer Application[^]
-
No, this isn't a programming question. I seem to recall that on some version of VC++, delete and delete[] do the same thing, am I right in thinking that ? If so, does anyone have an online reference to the fact ? Note: I NEVER use delete without the [] to delete an array, but I thought that proper form didn't make a difference, is all. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
Raymond Chen: Mismatching scalar and vector new and delete[^] Stability. What an interesting concept. -- Chris Maunder