Re: [Firebird-devel] addRef and release

2019-09-20 Thread Alex Peshkoff via Firebird-devel

On 20.09.2019 22:42, Jiří Činčura wrote:

Before returning some ref-counted object from a function it's reference
count is increased - therefore no need to call addRef() for an object
returned by some function. When a pointer is going away (no matter due

Just to make sure, by "going away" you mean "no longer needed", right?


yes




to end of life of stack frame or when class instance is destroyed)
release() should be called.
If it's possible to have RAII holder for an object (a kind of reference
pointer) - it would be very good programming practice on my mind.

Something like std::unique_ptr? Or anything specific for Firebird you have in 
mind?



With custom deleter calling release() - why not?




Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel


Re: [Firebird-devel] addRef and release

2019-09-20 Thread Jiří Činčura
> Something like std::unique_ptr? Or anything specific for Firebird you 
> have in mind?

For example something like RefPtr with REF_NO_INCR, to be precise.

-- 
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/


Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel


Re: [Firebird-devel] addRef and release

2019-09-20 Thread Jiří Činčura
> Before returning some ref-counted object from a function it's reference 
> count is increased - therefore no need to call addRef() for an object 
> returned by some function. When a pointer is going away (no matter due 

Just to make sure, by "going away" you mean "no longer needed", right?

> to end of life of stack frame or when class instance is destroyed) 
> release() should be called.

> If it's possible to have RAII holder for an object (a kind of reference 
> pointer) - it would be very good programming practice on my mind.

Something like std::unique_ptr? Or anything specific for Firebird you have in 
mind?

-- 
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/


Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel


Re: [Firebird-devel] addRef and release

2019-09-20 Thread Alex Peshkoff via Firebird-devel

On 20.09.2019 21:59, Jiří Činčura wrote:

Hi *,

I'm bit lost in the logic  of`addRef` and `release`. So better to ask, than 
cause some leaks, right?

Let's suppose I call `IExternalContext::getAttachment` in a method and assign 
it to local variable. Do I have to call `addRef` after getting the instance? Do 
I have to explicitly call `release` before end of the method?

Let's suppose I call `IExternalContext::getAttachment` in a constructor and 
assign it to the field of the class. Do I have to call `addRef` in that 
constructor? Do I have to call `release` later in destructor?


Two mentioned cases have absolutely no difference therefore single answer.

Before returning some ref-counted object from a function it's reference 
count is increased - therefore no need to call addRef() for an object 
returned by some function. When a pointer is going away (no matter due 
to end of life of stack frame or when class instance is destroyed) 
release() should be called.


If it's possible to have RAII holder for an object (a kind of reference 
pointer) - it would be very good programming practice on my mind.





Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel


[Firebird-devel] addRef and release

2019-09-20 Thread Jiří Činčura
Hi *,

I'm bit lost in the logic  of`addRef` and `release`. So better to ask, than 
cause some leaks, right?

Let's suppose I call `IExternalContext::getAttachment` in a method and assign 
it to local variable. Do I have to call `addRef` after getting the instance? Do 
I have to explicitly call `release` before end of the method?

Let's suppose I call `IExternalContext::getAttachment` in a constructor and 
assign it to the field of the class. Do I have to call `addRef` in that 
constructor? Do I have to call `release` later in destructor?

Thanks.

-- 
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/


Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel