Few questions (okay, in fact: lots of questions)

Started by
23 comments, last by Marco H 19 years, 3 months ago
Every call to operator new must be matched by exactly one call to operator delete. Every call to operator new[] must be matched by exactly one call to operator delete[]. Every call to malloc should be matched by exactly one call to free. It is generally good advise to avoid using malloc in C++ because this saves you the worry of trying to distinguish between what you should delete([]) and what you should free.

Quote:Original post by _DarkWIng_
~something() {    if ( dynamic_one != NULL ) delete[] dynamic_one;}


No need to test for nullness. The C++ standard guarantees that deleting a null pointer is safe, so the test is redundant.

Enigma
Advertisement
Thanks, that helped me a lot.

But now: another question :)
My code to load a texture looks like that:

GLubyte * imageData;  //store the raw dataGLuint texID;  //texture nametexID = loadAnyImageFormat(imageData, file_name);  //returns the name and fills the image dataglGenTextures(1,texID);glBindTexture(GL_TEXTURE_2D,texID);gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGB8,width,height,type,GL_UNSIGNED_BYTE,imageData);  //build the texture


Everything is okay, nothing to complain. But now I want to delete this texture and there is something that is not totally clear to me.
If I call "glDeleteTextures(1,&texID);", is the "imageData" automatically deleted or do I have to do this myself?
Quote:Original post by Enigma
No need to test for nullness. The C++ standard guarantees that deleting a null pointer is safe, so the test is redundant.

Thanks for correction. I'm always forgetting this.

Quote:Original post by Marco H
If I call "glDeleteTextures(1,&texID);", is the "imageData" automatically deleted or do I have to do this myself?

You have to delete imageData yourself. You don't have to wait until deleting texture. You can get rid of it right after uploading it to opengl (after gluBuild2DMipmaps).
You should never let your fears become the boundaries of your dreams.
You are right! Thanks for the tip, it is really good to know :)

Seems like I found my mistake an now my program does not crash even if I load a level a hundred times :)

Thanks, thanks and thanks again :-)
One more question... is it allowed to post information for my project here in this forum? It would be a kind of advertising, but perhaps it could help me to improve it a bit :-)

This topic is closed to new replies.

Advertisement