Board index » cppbuilder » Would this be a smart ptr problem?

Would this be a smart ptr problem?

The discussion about smart pointers in this group seems to say that it's
not safe (for now) to use server functions that return pointers. But
Excel has the indispensable get_Range() function that return a
Excel_<x>::RangePtr pointer that is needed for many other purposes.
Would RangePtr be a smart pointer, and so each time get_Range() is
called would I be causing Excel to leak memory?
 

Re:Would this be a smart ptr problem?


Hi Jim,

that particular instance wouldn't be a problem.  The smart pointers are only
a problem when they are [in] parameters.  In this case get_Range is
returning a pointer, so it's an [out] parameter.

If on the other hand, you had a function set_Range which took a smart
pointer argument, then it would be an [in] parameter and because of the BCB
bug, you would be leaking a reference to the pointer passes (i.e., it would
have one additional reference which it shouldn't have).

If you want a work-around for this bug, I've made a recent posting on the
'PLEASE READ.  BUILDER COM SUPPORT BROKEN' thread which details a
work-around.

Phil.

Quote
"Jim Melsom" <jmel...@uniserve.com> wrote in message

news:39ED292F.4763@uniserve.com...
Quote
> The discussion about smart pointers in this group seems to say that it's
> not safe (for now) to use server functions that return pointers. But
> Excel has the indispensable get_Range() function that return a
> Excel_<x>::RangePtr pointer that is needed for many other purposes.
> Would RangePtr be a smart pointer, and so each time get_Range() is
> called would I be causing Excel to leak memory?

Re:Would this be a smart ptr problem?


Thanks again, Phil.

Jim

Quote
Phil Parker wrote:

> Hi Jim,

> that particular instance wouldn't be a problem.  The smart pointers are only
> a problem when they are [in] parameters.  In this case get_Range is
> returning a pointer, so it's an [out] parameter.

> If on the other hand, you had a function set_Range which took a smart
> pointer argument, then it would be an [in] parameter and because of the BCB
> bug, you would be leaking a reference to the pointer passes (i.e., it would
> have one additional reference which it shouldn't have).

> If you want a work-around for this bug, I've made a recent posting on the
> 'PLEASE READ.  BUILDER COM SUPPORT BROKEN' thread which details a
> work-around.

> Phil.

> "Jim Melsom" <jmel...@uniserve.com> wrote in message
> news:39ED292F.4763@uniserve.com...
> > The discussion about smart pointers in this group seems to say that it's
> > not safe (for now) to use server functions that return pointers. But
> > Excel has the indispensable get_Range() function that return a
> > Excel_<x>::RangePtr pointer that is needed for many other purposes.
> > Would RangePtr be a smart pointer, and so each time get_Range() is
> > called would I be causing Excel to leak memory?

Other Threads