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
> > [email protected]
> > https://lists.gnu.org/mailman/listinfo/gnunet-developers
> > 

> pub  1024D/48426C7E 2006-12-18 Christian Grothoff <[email protected]>
> uid                            Christian Grothoff <[email protected]>
> uid                            Christian Grothoff <[email protected]>
> uid                            Christian Grothoff <[email protected]>
> uid                            Christian Grothoff <[email protected]>
> sub  4096g/6433E483 2006-12-18




_______________________________________________
GNUnet-developers mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnunet-developers

Reply via email to