Eric Blake wrote:
> obstack_printf is glibc specific, and not part of the gnulib obstack
> module.  Is there interest in supporting obstack_printf alongside the
> vasnprintf family?

Yes. Since glibc has it, and it can be implemented in a portable way, it
is welcome if gnulib provides a substitute. Can you write it? I'll be
away for a week.

> it is rather wasteful the
> amount of strings that it puts through asprintf followed by copying to the
> obstack rather than direct use of obstack_printf

Sure. That's what vasnprintf() is made for. I would implement
obstack_printf by calling vasnprintf with
     n = max (number of bytes available in the current obstack segment, 2000),
i.e. write directly into the obstack if the number of available bytes is >= 
2000,
and use a stack-allocated buffer (like vfprintf-posix does) if it is < 2000.
This way, the average cost of malloc is kept low, since a malloc only occurs
when the output is large _and_ doesn't fit.

Bruno



Reply via email to