Xref: utzoo comp.lang.c:10605 comp.lang.c++:1222 Path: utzoo!dciem!nrcaer!scs!spl1!laidbak!att!pacbell!ames!umd5!uflorida!gatech!mcnc!rti!xyzzy!meissner From: meissner@xyzzy.UUCP (Michael Meissner) Newsgroups: comp.lang.c,comp.lang.c++ Subject: Re: I/O implementation in C and C++ Message-ID: <893@xyzzy.UUCP> Date: 3 Jun 88 12:00:55 GMT Article-I.D.: xyzzy.893 References: <462@polari.UUCP> Reply-To: meissner@xyzzy.UUCP (Michael Meissner) Organization: Data General (Languages @ Research Triangle Park, NC.) Lines: 23 In article <462@polari.UUCP> rlb@polari.UUCP (rlb) writes: | | | I find it interesting that both K&R (C) and Stroustrup (C++) give | I/O package implementation examples in which buffer allocation takes | place at the first I/O, rather than in the "open". The obvious disadvantage | to this is error detection; the programmer is surprised to discover that | although the "open" succeeded, the first I/O fails because of lack of | memory (and of course it is usually easier to isolate the open and test | its status than to do the same for the first I/O). The only advantage I | can think of is that if an "open" is performed but no I/O is requested, | you've saved a bit of memory. Are there other advantages? | -Ron Burk While I'm firmly in the camp about open allocating the buffer, I will concede that doing the allocation at the first I/O has another advantage: if you use setbuf/setvbuf/setlinebuf/setbuffer on the file, you don't have to do an allocate/free combination to first allocate the default buffer, and switch to the user's buffer. -- Michael Meissner, Data General. Uucp: ...!mcnc!rti!xyzzy!meissner Arpa: meissner@dg-rtp.DG.COM (or) meissner%dg-rtp.DG.COM@relay.cs.net