Boost logo

Boost Users :

From: Scott Meyers (usenet_at_[hidden])
Date: 2006-03-08 00:26:56


I've been trying to get a handle on cost of using Boost.format by looking at the
interface, reading the docs, and, until my head exploded, looking at the source
code.

What I'd really like to know is whether simple output without reordering incurs
the cost of an allocation (for a string or maybe a stringstream) for each
argument. For example, should I, as a user, expect the following to potentially
cost me three dynamic memory allocations?

   cout << format("%1% %2% %3%") % 86 % 100.55 % "Hello";

The doc says this:

> Since common stream implementations eventually call functions of the printf
family for the actual formatting of numbers, in general printf will be
noticeably faster than the direct stream operations And due to to the reordering
overhead (allocations to store the pieces of string, stream initialisation at
each item formatting, ..) the direct stream operations would be faster than
boost::format, (one cas expect a ratio ranging from 2 to 5 or more)

This suggests that per-argument buffering to support reordering may cost an
allocation per argument, but if there is no reordering, does one pay this cost?

I could figure this out on my own given enough time, but I'm hoping that others
familiar with this library already know the answer and can save me the trouble.

Thanks,

Scott


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net