Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Propor use of "delete"

Author
Message
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 23rd Jan 2011 06:40
Hey, I'm just wondering if I'm using the delete operator here properly.



Just that, Thanks.

http://ref.darkgdk.us/ <- Online DarkGDK Refernece. More content coming soon.
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 23rd Jan 2011 16:59
Yes, use "delete[]" when deleting arrays, and "delete" for single objects.

“C++ : Where friends have access to your private members.”
-Gavin Russell Baker
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 23rd Jan 2011 20:30
Another question:

what if I changed "delete[] buffer;" to "delete[64] buffer;"? Would that only delete the 64th element in the array?

http://ref.darkgdk.us/ <- Online DarkGDK Refernece. More content coming soon.
Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 23rd Jan 2011 20:33 Edited at: 25th Jan 2011 22:44
I'm mistaken, ignore me.


Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 24th Jan 2011 04:09
Well, "delete[64] buffer;" compiles with no complaints in MSVC9.

http://ref.darkgdk.us/ <- Online DarkGDK Refernece. More content coming soon.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 24th Jan 2011 07:14
Quote: "No. You would use "delete buffer[64]" if I'm not mistaken."


You are mistaken.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 24th Jan 2011 13:16 Edited at: 24th Jan 2011 13:17
if your buffer is an array of pointers, you can use delete buffer[64]; to delete 64th element (this is NOT your case),but i have never seen delete[64] buffer; syntax really

Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 24th Jan 2011 18:16
Quote: "to delete 64th element"


65th element.

And no, don't do that.

“C++ : Where friends have access to your private members.”
-Gavin Russell Baker
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 25th Jan 2011 00:29 Edited at: 25th Jan 2011 00:31
Actually:

char* buff=new char[64]; correct

delete buff; correct

delete buff[x]; incorrect because buff points to the memory. Each element hasn't been allocated separately.

delete &buff[x]; is also incorrect for the same reason exept for &buff[0];

Warning! May contain Nuts!
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 25th Jan 2011 06:09
Quote: "delete buff; incorrect"


Fixed that for you.


It's not that hard to understand; new requires delete, new[] requires delete[].

Login to post a reply

Server time is: 2024-11-19 14:50:21
Your offset time is: 2024-11-19 14:50:21