On 12.10.2010 20:35, Hyrum K. Wright wrote:
> 1) Return everything by value
>    Pros: simpler memory management, less overhead (?)
>    Cons: doesn't allow the return of NULL values, need to establish
> conventions to represent NULL objects (an isNull() method?)

Meh.

    inline operator bool() const { return (this->c_struct_pointer != 0); }

> 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)

This would be seriously horrible since any user of the library would
then have to invent their own way to manage the lifetime of these
objects (i.e., wrap them in smart pointers). Defeats the whole purpose
of having a C++ API in the first place IMHO.

> 3) Some combination of (1) & (2)
>    Pros: Can return guaranteed existing things by value, potentially
> NULL ones by pointer
>    Cons: Making the distinction between optional and required takes
> more effort, a heterogeneous API is more work for callers

Yup, so it is, so go with (1) and do it right. :)

-- Brane

Reply via email to