Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

RMS Matthew Stallman's magic library

Name: Anonymous 2011-01-06 12:33

Why is glibc's fwrite_unlocked faster than the write syscall?

Name: Anonymous 2011-01-06 22:57

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_)));

  if (((((_IO_FILE*)(&_IO_2_1_stdout_)))->_vtable_offset != 0
       || _IO_fwide (((_IO_FILE*)(&_IO_2_1_stdout_)), -1) == -1)
      && ((*(struct _IO_jump_t **) ((void *) &((struct _IO_FILE_plus *) (((_IO_FILE*)(&_IO_2_1_stdout_))))->vtable + (((_IO_FILE*)(&_IO_2_1_stdout_)))->_vtable_offset))->__xsputn) (((_IO_FILE*)(&_IO_2_1_stdout_)), str, len) == len
      && (__builtin_expect (((((_IO_FILE*)(&_IO_2_1_stdout_)))->_IO_write_ptr >= (((_IO_FILE*)(&_IO_2_1_stdout_)))->_IO_write_end), 0) ? __overflow (((_IO_FILE*)(&_IO_2_1_stdout_)), (unsigned char) ('\n')) : (unsigned char) (*(((_IO_FILE*)(&_IO_2_1_stdout_)))->_IO_write_ptr++ = ('\n'))) != (-1))
    result = (((2147483647)<(len + 1))?(2147483647):(len + 1));

  _IO_release_lock (((_IO_FILE*)(&_IO_2_1_stdout_)));
  return result;
}

.

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.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List