overloading operators for I/O

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Thu Feb 15 08:39:09 PST 2007


Walter Bright wrote:
> Michiel wrote:
>> Bill Baxter wrote:
>>
>>>> But it has the added advantage that there is no need for run-time
>>>> parsing of that string. C++ parses all << stuff at compile time.
>>>>
>>> I wonder how much difference that makes given that most IO tends to be
>>> slow anyway.   On a 1 GHz proc, with a disk that has 10msec seek time
>>> that means a hit to the disk can cost you ten million cycles, right?
>>>
>>> Spending a few cycles to parse a format string at runtime isn't going to
>>> kill you.
>>
>> Well, you're right of course. But strictly speaking it's still an
>> advantage. ;)
> 
> C++ iostreams has the further "advantage" of being neither 
> exception-safe nor thread-safe (since it manipulates global state in 
> order to do formatting). This is only excusable because iostreams was 
> added to C++ years before exception handling was and before anyone knew 
> anything about threaded programming.

It's a myth that iostreams benefit much the speed advantage of not 
needing to do type retrieval at runtime. They are marred by a convoluted 
design and the need to synchronize with C's stdio library. By the time 
you saved that penny, you've spent all of those pounds already.

Andrei




More information about the Digitalmars-d mailing list