Re: Converting int to string

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: r norman (rsn__at__comcast.net)
Date: 08/09/04


Date: Mon, 09 Aug 2004 08:52:26 -0400

On Mon, 09 Aug 2004 13:36:54 +0100, tom_usenet
<tom_usenet@hotmail.com> wrote:

>On Fri, 6 Aug 2004 09:48:34 +0900, "Kim, Seungtai" <stkim@ yujinrobot
>com> wrote:
>
>>"tom_usenet" <tom_usenet@hotmail.com> wrote in message news:9c94h0pqsboqucr3esto8on3faiviv8gin@4ax.com...
>>> On Thu, 05 Aug 2004 07:34:32 -0400, r norman <rsn_@_comcast.net>
>>> wrote:
>>>
>>> >I tend to agree with you. However, the fact is that I have also
>>> >created innumerable bugs by using sprintf format values with the wrong
>>> >type of value. The function itoa() is not standard C or C++ and you
>>> >have to remember about _itoa or _ultoa or all the other versions. And
>>> >also "modern" programming tends to use all sorts of data items beyond
>>> >char, int, or float.
>>> >
>>> >If you love good programming techniques, you will use the standard
>>> >methods. If you love good performance, then diligent attention to
>>> >your program design will yield far more effective results than relying
>>> >on a few little tricks.
>>>
>>> If you care about both portability and performance, you could write
>>> your own itoa style function (perhaps less error prone and more
>>> useful, e.g. with a stringLength reference argument that takes the
>>> capacity of the buffer on the way in and gives the length of the
>>> string on the way out).
>>>
>>> Tom
>>
>>You mean that the created function can have the higher portability
>>than the Standard method and the the higher performance than
>>the Implementation supportted method? Even less error prone and
>>more useful...
>>
>>If so, I want to see the example. Would you...?
>
>It's pretty easy to write a function (or overloaded function set) that
>is:
>
>1) Faster than the stringstream technique
>2) Faster than sprintf
>3) Portable (unlike _itoa)
>4) Less error prone than itoa or sprintf
>5) Works with different radices (up to 36)
>6) Indicates failure via an exception (since failure of an itoa type
>function is definitely exceptional)
>
>Whether you'll beat the performance of itoa I don't know - I haven't
>checked its source code (which may be assembler).

<snip code which probably exhibits these characteristics>

I would bet that if you spent as much time analyzing and refining the
design of your program as you did in creating this example, you would
get far better performance out of your overall program. It is probably
a very rare and exceptional program in which converting int to string
is the major determinant of performance. Therefore pulling even an
inefficient package out of the standard library is probably the most
efficient and effective technique from the perspective of getting the
entire application done correctly.



Relevant Pages

  • Re: Converting int to string
    ... >> You mean that the created function can have the higher portability ... >> than the Standard method and the the higher performance than ... Less portability for int type the limit 10 for large scale int type machine ...
    (microsoft.public.vc.stl)
  • Re: Converting int to string
    ... Seungtai" <stkim@ yujinrobot com> wrote in message ... > You mean that the created function can have the higher portability ... > than the Standard method and the the higher performance than ...
    (microsoft.public.vc.stl)
  • Re: Converting int to string
    ... Kim, Seungtai wrote: ... > You mean that the created function can have the higher portability ... > than the Standard method and the the higher performance than ...
    (microsoft.public.vc.stl)