template statistics

Steven Schveighoffer schveiguy at gmail.com
Thu Jun 4 03:00:26 UTC 2020


On 6/3/20 10:28 PM, Adam D. Ruppe wrote:
> On Thursday, 4 June 2020 at 01:38:50 UTC, Walter Bright wrote:
>> Furthermore, stdout has to acquire a mutex before writing to it:
> 
> No need for any of this on the OS level, a write up to like 4k is 
> guaranteed to be atomic.
> 
> It is the C buffer that isn't :(
> 
> And the C buffer is a consistent source of pain for user-interactive 
> i/o. Buffering makes a big performance difference when you are actually 
> outputting a block... but with user-interactive you rarely actually 
> *want* buffering since users want to see their results ASAP! And 
> remember, pipes are frequently user-interactive too and them not being 
> flushed frequently is a FAQ among new users, especially IDE users.
> 
> I kinda feel buffering should not be done across function boundaries for 
> stdout and stderr. Other files maybe.

I don't think you are consider the ramifications. You NEED a buffer, 
otherwise, e.g. you will be issuing system calls for writing 5 bytes, 
followed by an immediate system call for 5 more. And that isn't cheap. 
Locking a mutex would be dwarfed by that. Flushing on newlines is a 
reasonable compromise.

But it doesn't have to be a C buffer (unless you want to interact with 
printf).

There are good reasons to use C buffering for the standard handles. But 
it sucks that ALL Phobos I/O has to be based on it (including opening a 
file that you never use in a C call).

-Steve


More information about the Digitalmars-d mailing list