Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!brutus.cs.uiuc.edu!ginosko!uunet!mcsun!ukc!edcastle!aiai!ken From: ken@aiai.ed.ac.uk (Ken Johnson) Newsgroups: comp.lang.pascal Subject: Re: Algorithm for average time of day? Message-ID: <876@skye.ed.ac.uk> Date: 13 Sep 89 10:51:10 GMT References: <1780003@hpcc01.HP.COM> <898@dutrun.UUCP> <8Z2az8G00WB8M1AUcT@andrew.cmu.edu> Reply-To: ken@aiai.UUCP (Ken Johnson) Organization: AIAI, University of Edinburgh, Scotland Lines: 23 In article <8Z2az8G00WB8M1AUcT@andrew.cmu.edu> dl2p+@andrew.cmu.edu (Douglas Allen Luce) writes: >I'm trying to read the contents of a text file into memory and have a single >pointer to it. I quickly figured up a couple of different ways to do this: > >First count all the characters in the text file, then allocate enough memory >to hold it, then go back and read in the file. I figured this would be a bit >slower than: Here is an alternative. I can't spell it out in great detail because I don't know which operating system you are using. However, both MS/DOS and UNIX allow you to find the length of a file from information about it held in the disk directory. Read that information, then create a buffer of the right size and then read the disk into it. Good luck, -- Ken -- Ken Johnson, AI Applications Institute, 80 South Bridge, Edinburgh EH1 1HN E-mail ken@aiai.ed.ac.uk, phone 031-225 4464 extension 212 `I have read your article, Mr. Johnson, and I am no wiser than when I started.' -- `Possibly not, sir, but far better informed.'