[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [GNUnet-developers] [patch] add GNUNET_append_printf function
From: |
Andrew Cann |
Subject: |
Re: [GNUnet-developers] [patch] add GNUNET_append_printf function |
Date: |
Fri, 14 Feb 2014 21:50:58 +0800 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
It just seems cleaner to me to start with a buffer and realloc it a few times
until it's the size I want. Rather than malloc() and free() a bunch of
intermediate buffers of incrementally greater sizes. It involves less copies
aswell so long as the buffer can be realloc()ed in place.
Why do you say realloc is bad style?
- Andrew
On Fri, Feb 14, 2014 at 02:30:04PM +0100, Christian Grothoff wrote:
> Why not just use
>
> GNUNET_asprintf (&result, "%s" format, prefix, ...)?
>
> The only difference to your new API is that you imply a realloc and
> thus would not have to 'free' prefix, but I think that's still cleaner
> (I personally try to avoid realloc, it is kind-of bad style anyway).
>
> Just wondering...
>
> -Christian
>
> On 02/14/2014 01:01 PM, Andrew Cann wrote:
> > This patch adds a function which realloc()s a string and prints to the end
> > of
> > it. Useful for building up strings when you don't know how large a buffer to
> > allocate beforehand.
> >
> > I've also added the format(printf) __attribute__ to this and the other
> > *printf
> > functions.
> >
> > - Andrew
> >
> >
> >
> > _______________________________________________
> > GNUnet-developers mailing list
> > address@hidden
> > https://lists.gnu.org/mailman/listinfo/gnunet-developers
> >
> pub 1024D/48426C7E 2006-12-18 Christian Grothoff <address@hidden>
> uid Christian Grothoff <address@hidden>
> uid Christian Grothoff <address@hidden>
> uid Christian Grothoff <address@hidden>
> uid Christian Grothoff <address@hidden>
> sub 4096g/6433E483 2006-12-18