gt4586c@prism.gatech.EDU (WILLETT,THOMAS CARTER) (09/21/90)
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. -- thomas willett Georgia Institute of Technology, Atlanta gt4586c@prism.gatech.edu "Violence is the last refuge of the incompetent." - Salvor Hardin (Foundation)
dmr@csli.Stanford.EDU (Daniel M. Rosenberg) (09/21/90)
In <13963@hydra.gatech.EDU> gt4586c@prism.gatech.EDU (WILLETT,THOMAS CARTER) writes: >I would like to solicit some assistance in the use of FSRead. >... My question is: how do i know how much memory to allocate >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. FSRead looks like this: FUNCTION FSRead(refNum: INTEGER; VAR count: LONGINT; buffPtr: Ptr); How much memory do you allocate? Enough so that you can read count bytes of data into it. For example, if you want to read your file in 200 byte chunks, your buffPtr should point to an area of memory 200 bytes long. How do you get to the numbers lurking in the buffer? Well, golly, I do this in C and not Pascal, but you need to write or find functions out there that convert from 8 bit integers (or shorts or chars -- chars being the likeliest way Pascal sees them) to reals. Check your Pascal library functions. Good luck. -- # Daniel M. Rosenberg // Stanford CSLI // Chew my opinions, not Stanford's. # dmr@csli.stanford.edu // decwrl!csli!dmr // dmr%csli@stanford.bitnet
stevec@Apple.COM (Steve Christensen) (09/22/90)
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