On 12/22/10 13:47, Bruno Haible wrote:
> Why do people do this? It appears to be slower than just calling
> asprintf, because it has to parse the format string and produce
> the expansion twice.

In the case of coreutils, the snprintf (NULL, 0, ....) is invoked
just once, to find out the size of the buffer needed.  Then
the buffer is allocated (once) and sprintf (buf, size, ...) is
invoked many times on the same buffer.  For this sort
of application I expect that switching to asprintf would hurt
performance, since asprintf would need to allocate and free the buffer
many times.

Reply via email to