|
-
October 11th, 2010, 03:16 AM
#11
Re: 3D array memory allocation dimensions
 Originally Posted by Kositch
So like that?:
Code:
delete [] array3d[0][0]
delete [] array3d[0]
delete [] array3d
I hope, it's right now :-) There will be needed no for cycles?
Nope, you are still missing a ton of deletes. The syntax is;
the keyword is "delete []", which will delete the array allocated at pointer. Note that at no point in time do you specify the size of the object to be deleted. You need one delete per allocation, so in your case:
Code:
for (int x = 0; x < HEIGHT; ++x)
{
for (int y = 0; y < WIDTH; ++y)
{
delete [] test[x][y];;
}
delete [] test[x];
}
delete [] test;
Just delete in the oposite order that you allocated.
EDIT: Arrays are "fun" for learning, But I highly recommend you learn to use vectors. Understanding how an array works is important, but learning to use vectors correctly is even more important.
Last edited by monarch_dodra; October 11th, 2010 at 03:20 AM.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|