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 / Issues with properly deleting multi-dimensional arrays

Author
Message
_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 23rd Mar 2010 22:06 Edited at: 23rd Mar 2010 22:07
Hey people,

I have serious issues with deleting dynamically created multi-dimensional arrays!
I create them like this (example of one of the arrays):



Then, after using this array, I tried to delete it like this:



But the program crashes and I get this:

Quote: "Heap block at 0D500040 modified at 0D50FC48 past requested size of fc00"


How can I solve this problem?
Am I deleting the arrays the way it should be done?

Any help is greatly appreciated!

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 23rd Mar 2010 22:24 Edited at: 23rd Mar 2010 22:26
Well I never tried to delete arrays but my only idea is to try to delete it by counting down in the for loop instead of up (so you start with the last index). So I would think it would be this:

Good luck!

EDIT: Just saw this webpage: http://www.fredosaurus.com/notes-cpp/newdelete/50dynamalloc.html. So instead of the above code try this:


"So hold your head up high and know, it's not the end of the road"
My blog!
_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 23rd Mar 2010 22:38
Thanks for the quick response!
Unfortunatly it didn't change anything, it still crashes...

Here are the other two arrays that I use (just in case I messed something up there):



Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 23rd Mar 2010 23:01 Edited at: 23rd Mar 2010 23:10
instead of this:

try this:


Those are just guesses so I wouldn't be surprised if it didn't work.

EDIT: I tried compiling your code and I get the error but it points to the loop that allocates the 3rd dimension in the vert_store array. I also tried your code from the your first post and I didn't get an error, it just froze.

"So hold your head up high and know, it's not the end of the road"
My blog!
_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 23rd Mar 2010 23:32
Ok, that's how I tried right in the beginning, and it just freezes.

I think it's a pain that it is that difficult! It was so easy in Basic...

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 23rd Mar 2010 23:55 Edited at: 23rd Mar 2010 23:56
Well, I've read quite a few pages now and there seem to be many different ways to do this...
But I just can't figure out what's best.

What it comes down to is:
In Basic you could just write sth. like: dim MyArray(x,y,z)
Where x, y and z could be non-constant, no problem.
Then you could access the elements as usual...

But in C++ this seems to be an important thing, considering memory allocation and all...
What's the right way to this in C++??
(allocating and deleting)

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 24th Mar 2010 13:03 Edited at: 24th Mar 2010 13:12
Yey, pointer fun.

Quote: "Those are just guesses so I wouldn't be surprised if it didn't work."


Don't randomly guess.

To delete such an array you just have to do in the inverse of what you did to create it, i.e.:



A cleaner method would be to use a single dimension array and wrap it in a class, such as this:



Then you can do nice stuff like:



_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 24th Mar 2010 14:30
Wow, that's awesome dark coder!
Thanks a lot!

I will use the inverse thing for the function I needed this for, but I'll write such an array class sometime. I already thought about this aproach, but my lack of C++ skills didn't allow me to
Again, thanks so much.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.

Login to post a reply

Server time is: 2024-07-13 10:27:48
Your offset time is: 2024-07-13 10:27:48