Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!stevec From: stevec@Apple.COM (Steve Christensen) Newsgroups: comp.sys.mac.programmer Subject: Re: Help with FSRead Keywords: loading data files with FSRead Message-ID: <10349@goofy.Apple.COM> Date: 21 Sep 90 17:03:10 GMT References: <13963@hydra.gatech.EDU> Organization: Apple Computer Inc., Cupertino, CA Lines: 38 gt4586c@prism.gatech.EDU (WILLETT,THOMAS CARTER) writes: >I would like to solicit some assistance in the use of FSRead. I have an >application that needs to load data files which are text files full of >numbers. I am currently using the pascal READLN to load the data one line >at a time, and it is painfully slow. I have figured out that I can use >FSRead to read huge chunks of data off the disk in one big swallow rather than >a line at a time. My question is: how do i know how much memory to allowcate >to the buffer into which the data is placed, and how do i get to the numbers >which are lurking in the buffer, i.e. how do i go to the buffer and ask it >to give me integers or reals or whatever so i can put them into an array? >I would greatly appreciate any assistance. Thanks. You make the buffer as big as you want it to be. Other than trying to read the whole file into memory (if you have the space), you can't judge how much space to allocate to read in, say, 100 lines, unless the lines have a fixed size. One way to do it is to allocate a fairly small buffer (several K bytes could be considered small) to store chunks from the file. Then you could have a routine (ReadLine?) that returns the next line from the buffer. If the last line doesn't completely fit into the buffer, you'd store the first n characters in the output string, and then call FSRead to re-fill the buffer. This method requires a variable for the current index into the buffer, and one for the size of the buffer (initially set to the actual size of the buffer, but updated by what's in the ioNumDone field of FSRead's parameter block). As far as processing the string into individual integers, you'll have to do that yourself. There are some utilities for doing this (StringToNum and some SANE routines), but you'll have to parse the line into its individual parts first. Kind of a pain, I know... steve -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ whoami? Steve Christensen snail: Apple Computer, 20525 Mariani Ave, MS-81CS, Cupertino, CA 95014 Internet: stevec@goofy.apple.com AppleLink: stevec CompuServe: 76174,1712