Archived

This topic is now archived and is closed to further replies.

lackluster

Deleting Damage

Recommended Posts


      
.....
a_ColSize = new long [cbCols-1];
a_ColType = new long [cbCols-1];
.....
.....
delete a_ColSize; // DAMAGE

delete a_ColType; // DAMAGE

      
Here's the (run-time) error I'm getting from MSVC .NET :
quote:
DAMAGE after normal block #34 after 0xffffff { #34 = Random Number } { 0xffffff = Random Address }
Can anybody explain to me my error here? I can't seem to figure it out. I've never used new / delete before, so it's most likely a newbie thing I'm overlooking. Edited by - lackluster on March 23, 2002 12:58:46 AM Edited by - lackluster on March 24, 2002 1:00:53 AM

Share this post


Link to post
Share on other sites
well i do know this
a_ColSize and a_ColType are pointers to arrays
so delete them like this

delete [] a_ColSize;
delete [] a_ColType;



"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T

Share this post


Link to post
Share on other sites
You usally get this message when you dance around in memory you yourself did not allocate, then you try to delete the dynamic allocation. Say for example you dynaminally allocate at memory address 3000 - then you access memory address 3001...after you try to delete the allocation - You "damaged" a section of memory. Damage in this essence means that you filthed up someone elses playground

I got this DAMAGE error message when i allocated an array and started going beyond the bounds of it - when the class went out of scope, and the delete got called - BAM! this error message pops up.

Share this post


Link to post
Share on other sites
ncsu121978,
thanks for the tip, but it did not help - I have left it in my code, however because I believe you are correct

Programmer One,
Thanks for the reply, but it is not possible I am trying to access this memory, becasue I have set a breakpoint on delete and that''s exactly where it crashes.

Share this post


Link to post
Share on other sites
quote:
Original post by lackluster
Programmer One,
Thanks for the reply, but it is not possible I am trying to access this memory, becasue I have set a breakpoint on delete and that''s exactly where it crashes.


DOH

It crashes at delete because it is at thst point where your program says "WTF??! I can''t delete this!!! I don''t remember allocating anything here - holy shit...I just crapped my pants"

Trust me...I had the SAME problem - this is because you are off dancing around in memory. Check everywhere you access the dynamically allocated thingy.



_____________________________________________________

ICQ #: 149510932

Google - OpenGL - DirectX - Windows Guide Network - MSDN - Symantec Virus Info

"Imagination is more important than knowledge." - Albert Einstein

Share this post


Link to post
Share on other sites
If something accesses memory outside the bounds of your allocated array between the point of creation and deletion, you will get this error when you delete the array. What exactly are you doing between the new and delete?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I have this odd feeling its the fact that the arrays have the -1 in their size... maybe you have a good reason for it, I don''t know what your doing, so it could be just fine, but it just doesn''t look normal.

Well, I guess a better way to say it, is allocating it with that size is fine, but I suspect you''re using the full cbCols size of it, so the -1 makes it too small, causing damage when you write the final element. Can''t say for sure without seeing the code though.

Share this post


Link to post
Share on other sites
Yes, you were all correct - the array was going out of bounds (I expected the error when that occured, not when trying to delete) and it was because of the -1. I put this on because arrays are 0-based (not trying to insult anyone''s intelligence ) and this value was 1 based (0 is the bookmark column).

Share this post


Link to post
Share on other sites