Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!pt.cs.cmu.edu!andrew.cmu.edu!dl2p+ From: dl2p+@andrew.cmu.edu (Douglas Allen Luce) Newsgroups: comp.lang.pascal Subject: Re: Algorithm for average time of day? Message-ID: <8Z2az8G00WB8M1AUcT@andrew.cmu.edu> Date: 10 Sep 89 14:29:28 GMT References: <1780003@hpcc01.HP.COM>, <898@dutrun.UUCP> Organization: Class of '91, Carnegie Mellon, Pittsburgh, PA Lines: 40 In-Reply-To: <898@dutrun.UUCP> 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: Read in a line of the text file. Allocate enough memory to hold it, and put it into memory. Do this for each line. The algorithm I worked up for reading it in line-by-line is like this: var totalpointer:pointer; pst:^string; st:string; begin reset(textfile); totalpointer:=nil; while not eof(textfile) do begin readln(textfile,st); getmem(pst,length(st)+1); {add one for string[0] byte} pst^:=st; if totalpointer=nil then totalpointer:=pst; end; end; The effect of this is to read the text file into memory and pointer totalpointer to it. I would figure this works IF getmem returns contiguous blocks of memory each time it is called in sequence; is this true? And are there other operations (other than new) that would interfere with getmem returning contiguous blocks? Thanks in advance, Douglas Luce Carnegie Mellon