Skip to main content
gamedev.net
🔒 Locked

Inlining SAFE_RELEASE()?

Started by Goblin 4 replies 3.7k views
Original Post
Goblin
Goblin
I'm just curious how I would go about turning this ever-so-useful DirectX macro into an inline function...
    
#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
The Goblin (madgob@aol.com)
Javelin
Javelin
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// Assumption is the mother of all fuckups...
Boki
Boki
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):

  
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
We are boki. The rest is known.
Goblin
Goblin
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!"
The Goblin (madgob@aol.com)
Boki
Boki
The better way would be to use the _com_ptr_t class defined in COMDEF.H or an equivalent class.

Bjørn.
We are boki. The rest is known.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.