Am Samstag, 18. Dezember 2004 22:30 schrieb Curt Arnold: > On Dec 18, 2004, at 3:02 PM, Tommi M�kitalo wrote: > > Hi, > > > > there is a problem printing thread-id on 64-bit: > > > > log4cxx uses "StringHelper::toString(int, apr_pool_t*)" to convert the > > current > > thread-id to a string. On my machine thead-id is 64 bit unsigned > > (unsigned > > long), but int is only 32 bit and signed. > > > > There is a elegant solution in c++: ostringstream. We can use > > ostringstream to > > build the whole message. There is less hassle with formatting types > > then and > > it is a portable solution. > > > > What do you think? > > Creating an ostringstream has a surprisingly high creation cost and > there have been at least some users that made reasonable cases for > avoiding STL dependency where possible. I wrote a pretty simplistic > 64-bit toString() equivalent in RelativeTimeFormat. Maybe if I brought > that into StringHelper. Just to fight at least a little for STL (I don't want to start a flame-war about STL): I created StringHelper::UlongToString-methods and benchmarked it against std::wostringstream. The result was, that for large numbers (>INT_MAX, where your optimization don't catch), it took 2.3 seconds to format 1000000 with UlongToString and 1.5 seconds with std::wostringstream (including std::wostringstream-creation). For small numbers UlongToString took 0.5 seconds.
Tommi
