>>1
Because it does not lock the global mutex on the file object. Locking a global resource has overhead. However, you should probably not use the unlocked versions of those functions. It is not thread/process-safe.
>>5
If you don't know how something works, you find out, which usually means:
1) Is source available? Read it!
2) Is source not available? Disassemble it, use symbols if any are available, otherwise, make sense of it without them.
>>9
I think our point here was that if you want to understand how something works, you read the implementation (be it source or compiled code). Reading the specification is just meant to show you how an interface is supposed to work, not how it actually works or what its implementation details are. When someone asks a question like "Why is x faster than y?", you usually look at implementation details to find the answer, not at the specification.
Name:
Anonymous2011-01-06 14:45
You also need to understand that fwrite is double-buffered. If you use write, it's only single buffered unless you created the file handle with buffering disabled. puts is probably single-buffered too.
>>10
And our point is that you don't have a clue what you're talking about. write doesn't lock anything, and the FILE mutex doesn't interact with other processes. Furthermore, locking a mutex is insignificant compared to the overhead of a syscall.
>>12
I was never talking about the specifics of write, puts, fwrite and so on. I was just talking about it in general. The same way you tell someone to google something or read SICP.
OP here, and I must confess that I had trouble discerning how puts works as I only found macro after macro, running it through the preprocessor didn't help much either.
If any of you could tell me the gist of what's going on I'd appreciate it,
int
_IO_puts (str)
const char *str;
{
int result = (-1);
size_t len = strlen (str);
_IO_acquire_lock (((_IO_FILE*)(&_IO_2_1_stdout_)));
What I'd rather like know now is why syscalls are so expensive, I thought they'd be rather cheap. All I'm looking for the least expensive way to write a character to the stdout file and I'm happy.
All right, so I should start a different thread and write to a buffer in memory and then return control to the program while letting the thread write the buffer to stdout?