Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Jul 2007 17:46:07 -0700 (PDT)
From:      youshi10@u.washington.edu
To:        "Heiko Wundram (Beenic)" <wundram@beenic.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Large gap between fwrite and write, and fread and read
Message-ID:  <Pine.LNX.4.43.0707161746070.22217@hymn01.u.washington.edu>
In-Reply-To: <200707170145.52781.wundram@beenic.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 17 Jul 2007, Heiko Wundram (Beenic) wrote:

> On Monday 16 July 2007 14:06:57 Garrett Cooper wrote:
>>     I ran some tests and I noticed a large difference in the cumulative
>> sums of fwrite(2) vs write(3) and fread(2) vs read(3) (3-fold
>> differences on a real machine).
>
> This difference is at least partially explained when looking
> at /usr/include/stdio.h, which defines the FILE structure: read/write on a
> file descriptor is (pretty much) a direct syscall with operating system
> specific semantics on a wide range of behavior, such as buffering, flushing
> and seeking in read/write-opened files, whereas fread/fwrite on FILE*'s is
> an "abstraction" of file access for which the stdio-API defines semantics,
> such as buffering, the time flushing takes place and seeking in
> read/write-opened files, across different flavors of POSIX-compatible libc's
> equally.
>
> As the stdio-interface is a "wrapper" (with indirect calls calling the syscall
> read at some point in time, see the FILE-structure definition), you'll have
> to expect a difference in runtime, too.
>
> (You mixed up f{read,write}(3) and {read,write}(2), just as a sidenote, which
> is also indicative of the difference: man3 is indicative of a libc
> implementation, whereas man2 generally contains syscall documentation)
>
> --
> Heiko Wundram

      Yeah, that's what I meant. I was rather tired when I made that post at 5:30 this morning. Heh.
      Thank you for the additional info though. That was brief, but comprehensive :).
-Garrett




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.43.0707161746070.22217>