07.04.2011 16:09, Vlad Khorsun wrote:

> To protect us from the more then one call of detach() for the same instance.
> Example :
>
> IAttachment *att = provider->attach(...);
> doSomething(att);
> att->detach();
>
> doSomething(IAttachment *att)
> {
>    if (something very bad happens)        // this could be really at the few 
> levels
>      att->detach();                                // deeper at whole call 
> stack
> }
>
> Well, we can decrement refcount in detach() on success only, but it sounds
> as (not necessary) complication of reference counting policy.

Point taken, thanks.

> I understand your concerns. BTW, changing way to create objects from
>
> IAttachment *attach(...)
>
> by
>
> void attach(..., **IAttachment)
>
> allows us to use smart pointers and make no additional call of release() :
>
> {
>      smart_ptr<IAttachment>  att = NULL;
>      provider->attach(..., att.refPtr());        // refcnt == 1 here !
>      doSomething(att);
>      att->detach();                        // refcnt == 1
> }                                            // ~smart_ptr will decrement 
> refcnt

True, but my concerns are about the languages without smart pointers :-)


Dmitry

------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to