From owner-freebsd-hackers@FreeBSD.ORG Tue Jul 17 00:46:16 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3C90216A401 for ; Tue, 17 Jul 2007 00:46:16 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from mxout2.cac.washington.edu (mxout2.cac.washington.edu [140.142.33.4]) by mx1.freebsd.org (Postfix) with ESMTP id 1C71313C481 for ; Tue, 17 Jul 2007 00:46:16 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from hymn01.u.washington.edu (hymn01.u.washington.edu [140.142.8.55]) by mxout2.cac.washington.edu (8.13.7+UW06.06/8.13.7+UW07.06) with ESMTP id l6H0k7oP003027 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 16 Jul 2007 17:46:08 -0700 Received: from localhost (localhost [127.0.0.1]) by hymn01.u.washington.edu (8.13.7+UW06.06/8.13.7+UW07.03) with ESMTP id l6H0k7it011507; Mon, 16 Jul 2007 17:46:07 -0700 X-Auth-Received: from [192.55.52.3] by hymn01.u.washington.edu via HTTP; Mon, 16 Jul 2007 17:46:07 PDT Date: Mon, 16 Jul 2007 17:46:07 -0700 (PDT) From: youshi10@u.washington.edu To: "Heiko Wundram (Beenic)" In-Reply-To: <200707170145.52781.wundram@beenic.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-PMX-Version: 5.3.2.304607, Antispam-Engine: 2.5.1.298604, Antispam-Data: 2007.7.16.172234 X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='NO_REAL_NAME 0, __CT 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0' Cc: freebsd-hackers@freebsd.org Subject: Re: Large gap between fwrite and write, and fread and read X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Jul 2007 00:46:16 -0000 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