On Sep 21, 10:23 am, Aman JIANG <AmanJI...@gmail.com> wrote:
> On 9 20 , 8 29 , James Kanze <james.ka...@gmail.com> wrote:
[...]
> I think use 'stringstream' to do this work is still expensive,
In what way? It might use dynamic allocation, but then, if you
use std::string, you use dynamic allocation. How much depends;
if your implementation of std::string uses the short string
optimization, and the strings you generate fit into the short
string, it's possible that there is no dynamic allocation
anywhere.
In general, the relative performance will depend on the
implementation. I've used implementations where
std::ostringstream was about the same speed as sprintf, maybe
even faster for some things, and I've used implementations where
it was almost an order of magnitude slower.
> although it must be faster than boost::lexical_cast. We know
> that 'strstream' was "deprecated" in C++98.
So. It's still there, and will be for a long time.
> Is there another way to do this, no stream, and no old C-style
> functions, please ?
You can write the conversion routines yourself. Since you don't
need all of the formatting options, you should be able to come
up with something considerably faster than any of the standard
functions. For integral types, it's actually not very
difficult. For floating point types, on the other hand...
correctly converting floating point is far from trivial.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34