laniik wrote:[color=blue]
> i dont know this for sure, but I have heard that the atof function is
> fairly slow. and that i could speed up reading time by writing my own
> atof function. so maybe using .get() with my own atof will be faster
> than <<.
>
> also, does anyone know how << turns what it reads in into a float?
> wonder how fast that part is.
>
> ill try the memory allocation idea, ill try that, that makes sense.
>
> the list idea might speed things up, but I need to have random access
> abilities with this array.
>
> thanks everyone![/color]
I've heard things like this often. The next question would be, why
provide library functions if they are useless and slow? One factor is
of course that the library routines are very general. Here's an
implementation I found with google:
http://www.jbox.dk/sanos/source/lib/strtod.c.html
The scaling loop could be eliminated in trade for accuracy:
int scale = 1;
[...]
if (*p == '.') {
p++;
while (isdigit(*p)) {
number = number * 10. + (*p - '0');
p++;
scale *= 10;
}
}
[...]
return number / scale;
Regards,
Mike