[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: object-model: Return by value, reference or pointer? (or something else?)

From: Hyrum K. Wright <hyrum_wright_at_mail.utexas.edu>
Date: Wed, 13 Oct 2010 14:29:39 -0500

On Wed, Oct 13, 2010 at 11:51 AM, Steinar Bang <sb_at_dod.no> wrote:
>>>>>> "Hyrum K. Wright" <hyrum_wright_at_mail.utexas.edu>:
>
>> 2) Return everything by pointer
>>    Pros: can represent the NULL value, potentially less memory overhead
>>    Cons: more complex memory management (caller must delete returned value)
>
> Um... why must the caller delete the returned value?  I thought you were
> using refcounting smartpointers?

Refcounting smartpointers are used to avoid duplication of the
underlying C structures, but they are completely private. I've got
serious reservations about exposing that complexity in the external
object interfaces. Given those reservations, the API would just
return a vanilla pointer, which leaves the caller the responsibility
of freeing it.

> Generally 1 gives a nicer API.  But if you have any inheritance and
> virtual methods going, then 2 is simplest.

No inheritance or virtual stuff, as of yet, so not a concern.

-Hyrum
Received on 2010-10-13 21:30:16 CEST

This is an archived mail posted to the Subversion Dev mailing list.