From owner-freebsd-hackers@FreeBSD.ORG Tue Jul 17 00:18:04 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 EBFE716A404 for ; Tue, 17 Jul 2007 00:18:04 +0000 (UTC) (envelope-from wundram@beenic.net) Received: from mail.beenic.net (mail.beenic.net [83.246.72.40]) by mx1.freebsd.org (Postfix) with ESMTP id B12F513C48E for ; Tue, 17 Jul 2007 00:18:04 +0000 (UTC) (envelope-from wundram@beenic.net) Received: from phoenix (hnvr-4db2fdce.pool.einsundeins.de [77.178.253.206]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.beenic.net (Postfix) with ESMTP id 075BEA44529 for ; Tue, 17 Jul 2007 01:44:22 +0200 (CEST) From: "Heiko Wundram (Beenic)" Organization: Beenic Networks GmbH To: freebsd-hackers@freebsd.org Date: Tue, 17 Jul 2007 01:45:52 +0200 User-Agent: KMail/1.9.7 References: <469B5F61.1060805@u.washington.edu> In-Reply-To: <469B5F61.1060805@u.washington.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200707170145.52781.wundram@beenic.net> 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:18:05 -0000 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=20 at /usr/include/stdio.h, which defines the FILE structure: read/write on a= =20 file descriptor is (pretty much) a direct syscall with operating system=20 specific semantics on a wide range of behavior, such as buffering, flushing= =20 and seeking in read/write-opened files, whereas fread/fwrite on FILE*'s is= =20 an "abstraction" of file access for which the stdio-API defines semantics,= =20 such as buffering, the time flushing takes place and seeking in=20 read/write-opened files, across different flavors of POSIX-compatible libc'= s=20 equally. As the stdio-interface is a "wrapper" (with indirect calls calling the sysc= all=20 read at some point in time, see the FILE-structure definition), you'll have= =20 to expect a difference in runtime, too. (You mixed up f{read,write}(3) and {read,write}(2), just as a sidenote, whi= ch=20 is also indicative of the difference: man3 is indicative of a libc=20 implementation, whereas man2 generally contains syscall documentation) =2D-=20 Heiko Wundram Product & Application Development =2D------------------------------------ Office Germany - EXPO PARK HANNOVER =20 Beenic Networks GmbH Mail=E4nder Stra=DFe 2 30539 Hannover =20 =46on +49 511 / 590 935 - 15 =46ax +49 511 / 590 935 - 29 Mail wundram@beenic.net Beenic Networks GmbH =2D------------------------------------ Sitz der Gesellschaft: Hannover Gesch=E4ftsf=FChrer: Jorge Delgado Registernummer: HRB 61869 Registergericht: Amtsgericht Hannover