Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualjoew

Posted 29 October 2012 - 08:20 PM

And of course, the IDE in debug mode didn't give me the error (Or even a warning message).

The reason is because it is not a warning or error to the language. Also this is a big reason that you should use initializer lists in all constructors to initialize the class members, or in the rare case that you don't (say in a vector4 or matrix44) you need to be careful never to use it until it has been assigned a value. Note the reason it works fine in debug mode is that values will be initialized whereas in release mode they are not.

First Tip: Delete dynamically allocated memory as soon as possible. Whenever you do, set the pointer to null.

I disagree with both. It is actually much better to reuse dynamically allocated memory at runtime than to delete and reacquire. I would only delete when it is no longer needed. Although this is really a non-issue if you are using C++11 due to having std::unique_ptr, std::shared_ptr, and std::weak_ptr.

Regarding setting the pointer to null after deletion this is something I absolutely disagree with and is just inviting bugs to linger in your codebase. By setting to null you won't catch any double delete errors, etc which would be found and handled easily by attempted to delete something that has already been deallocated.

#2joew

Posted 29 October 2012 - 08:19 PM

And of course, the IDE in debug mode didn't give me the error (Or even a warning message).

The reason is because it is not a warning or error to the language. Also this is a big reason that you should use initializer lists in all constructors to initialize the class members, or in the rare case that you don't (say in a vector4 or matrix44) you need to be careful never to use it until it has been assigned a value. Note the reason it works fine in debug mode is that values will be initialized whereas in release mode they are not.

First Tip: Delete dynamically allocated memory as soon as possible. Whenever you do, set the pointer to null.

I disagree with both. It is actually much better to reuse dynamically allocated memory at runtime than to delete and reacquire. I would only delete when it is no longer needed. Although this is really a non-issue if you are using C++11.

Regarding setting the pointer to null after deletion this is something I absolutely disagree with and is just inviting bugs to linger in your codebase. By setting to null you won't catch any double delete errors, etc which would be found and handled easily by attempted to delete something that has already been deallocated.

#1joew

Posted 29 October 2012 - 08:19 PM

And of course, the IDE in debug mode didn't give me the error (Or even a warning message).

The reason is because it is not a warning or error to the language. Also this is a big reason that you should use initializer lists in all constructors to initialize the class members, or in the rare case that you don't (say in a vector4 or matrix44) you need to be careful never to use it until it has been assigned a value. Note the reason it works fine in debug mode is that values will be initialized whereas in release mode they are not.

First Tip: Delete dynamically allocated memory as soon as possible. Whenever you do, set the pointer to null.

I disagree with both. It is actually much better to reuse dynamically allocated memory at runtime than do delete and reacquire. I would only delete when it is no longer needed. Although this is really a non-issue if you are using C++11.

Regarding setting the pointer to null after deletion this is something I absolutely disagree with and is just inviting bugs to linger in your codebase. By setting to null you won't catch any double delete errors, etc which would be found and handled easily by attempted to delete something that has already been deallocated.

PARTNERS