#define SAFE_RELEASE(p) { if ( (p) ) { (p)->Release(); (p) = 0; } }
Thanks, appreciated!
-----------------
The Goblin (madgob@aol.com)
-----------------
"Before critisizing somebody, walk a mile in their shoes. That way, when you do critisize them, not only will you be a mile away, but you'll also have their shoes!"
Edited by - Goblin on August 7, 2001 2:12:04 PM
Inlining SAFE_RELEASE()?
I'm just curious how I would go about turning this ever-so-useful DirectX macro into an inline function...
May I ask why you want it as an inline function...? I don''t think you can make it any faster than it already is...
// Javelin
-- Why do something today when you can do it tomorrow... --
// Javelin
-- Why do something today when you can do it tomorrow... --
Hm, to do SAFE_RELEASE as an inlined function, one has to pass a pointer to a pointer to be able to set it to NULL. Sp the function may look like this (not tested nor used):
or
BTW: I agree with Javelin. There is actually no reason to do so.
Bjørn.
Edited by - Boki on August 7, 2001 4:34:07 PM
template < class T >void SafeRelease( T** p ){ if ( *p != NULL ) { (*p)->Release(); (*p) = NULL; }}
or
void SafeRelease( IUnknown** p ){ if ( *p != NULL ) { (*p)->Release(); (*p) = NULL; }}
BTW: I agree with Javelin. There is actually no reason to do so.
Bjørn.
Edited by - Boki on August 7, 2001 4:34:07 PM
Well, I was under the impression that it is better to use inline, constant, and enum in favor of #define.
I suppose because I figured if I''m going to program in C++ over C, may as well go all the way, right?
-----------------
The Goblin (madgob@aol.com)
-----------------
"Before critisizing somebody, walk a mile in their shoes. That way, when you do critisize them, not only will you be a mile away, but you''ll also have their shoes!"
I suppose because I figured if I''m going to program in C++ over C, may as well go all the way, right?
-----------------
The Goblin (madgob@aol.com)
-----------------
"Before critisizing somebody, walk a mile in their shoes. That way, when you do critisize them, not only will you be a mile away, but you''ll also have their shoes!"
There is a reason to use an inline version of the function instead of a macro: typechecking! The object code created will be the same (maybe not in all cases) but you get compile time errors as opposed to runtime crashes.
The better way would be to use the _com_ptr_t class defined in COMDEF.H or an equivalent class.
Bjørn.
Bjørn.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement