Stray pointers

Eljay Love-Jensen eljay@adobe.com
Tue Mar 23 15:15:00 GMT 2004


Hi Bruno,

Correct.  Performance.

So always do this when declaring a pointer:

Foo* pFoo = NULL; // or else "= new Foo"

And do this when deleting a pointed to object:

delete pFoo;
pFoo = NULL;

...unless you've determined (via profiling) the performance penalty is too 
high for your application.

Or try to use std::auto_ptr to help with your pointer resource management. 
Except when the performance penalty is too high for your application.

Or considering using one of the more memory management friendly languages, 
such as Java.  (That's "friendly" in the sense of "safe and easy; one less 
thing to worry about".)

Sincerely,
--Eljay



More information about the Gcc-help mailing list