Re: Behaviour of getters wrt dup/ref



On Fri, 2007-09-14 at 10:35 -0400, Alexander Larsson wrote:
> 
> char *      g_data_input_stream_get_line (GDataInputStream *data_stream,
>                                           gsize             *length,
>                                           GCancellable     *cancellable,
>                                           GError           **error);
> 
> This actually reads new data from the stream, so it has to dup. One
> could imagine a similar call that returns some form of object instead
> of a string. 

Hi Alex,

I think it's pretty common in glib and pango at least to return
g_strdup'ed strings.  The no-ref-count rule is mostly for objects that
have a literal ref/unref pair.

Other than that, for functions that return read data from the stream,
some people may have reasons to want to avoid malloc/free'ing on each
line.  One way to work around that is to have the function take a
GString, so you can reuse the buffer from the previous line.  I know
most people are not a big fan of that idea though.

-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]