"Aman JIANG" <Am*******@gmai l.comwrote in message
news:11******** **************@ y42g2000hsy.goo glegroups.com.. .
: On Sep 22, 4:59 pm, "Ivan Vecerina"
: <_INVALID_use_w ebfo...@ivan.ve cerina.comwrote :
: If iostream is too slow on your platform for your application, the
: performance-sensitive way to go is the printf family of functions.
: Because you might want to use some platform-specific extension
:
: I don't want to use any 'platform-specific extension', it isn't cross-
: platform code :( Otherwise maybe I can research the floating point
: format on all platforms...
:
: to make it safe, it could be a good idea to wrap it behind
: your own function - using the buffer-allocation and format-
: specification policy you want.
: As to rewriting or adapt a dtoa function into your application,
: I doubt it would be a sensible priority in terms of performance
: optimization (there should be more important things to tune...)
:
: It's hard. I have no idea to confirm the size of the buffer. for
: double, it can be 316 bytes, on my platforms, and i don't know the
: sizes on other platforms...
If you want a more precise answer than what you've obtained so far,
you need to also say more about what you want:
- what allocation strategy would you like to rely on for the
returned character buffer?
- what output formats do you want to support?
I personally use a wrapper over platform-specific variants
of sprintf, which returns the result as an std::string
(using a stack buffer for the initial output if possible, and
a dynamically allocated buffer for larger outputs - relying
e.g. on _vscprintf do determine buffer size).
But if I am writing to a file, fprintf does the job well.
If you really want a custom solution, you should be able to find
some open source implementation to start from... look
for dtoa() or fcvt() as common low-level function names.
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <
http://www.brainbench.com