Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!yale!venus!yalevm!maine!io92203 From: IO92203@MAINE.BITNET (Scott Maxell) Newsgroups: comp.lang.pascal Subject: Re: FILES and pointers Message-ID: <91112.130537IO92203@MAINE.BITNET> Date: 22 Apr 91 17:05:37 GMT References: <1991Apr22.014013.7390@usenet.ins.cwru.edu> Organization: University of Maine System Lines: 77 >Say I want to save a dynamically sized structure. People >have suggested linked lists, but those can be very slow. >Someone else suggested the following: > >type > bufferptr=^buffer; > buffer=array[1..64000] of byte; >var > p: bufferptr; >begin > getmem(p,(required size)); > ... > freemem(p,(required size)); > ... >end. > >The problem is that I need to save this to disk so that it can >be recalled as quickly as possible. Instead of a text file >with numbers written on it (way too slow and too big), I need >a FILE of something. But a FILE of what and how large will the >file be? > >Ideas: > >FILE of bufferptr > dumb, it only saves address > >FILE of bufferptr^ > is this even legal? if it is, this looks like the > proper solution > >FILE of buffer > that has way to much disk storage space. I need to > minimize both disk space and heap space required > although minimizing disk storage space seems a bit > more important > >Any suggestions or ideas? You might try using an untyped file and BlockRead/BlockWrite. To open the untyped file, you should specify a record length of 1 since you want a file of BYTE. File is declared: FileVar : File; ASSIGN (FileVar, 'filename.ext'); RESET (FileVar, 1); To read the file, you would use: BLOCKREAD (FileVar, Buffer, SizeOf (Buffer), Result) Result: Result : Word; Result returns the number of bytes actually read from the file if it differs from SizeOf (Buffer). BlockWrite works the same way: BLOCKWRITE (FileVar, Buffer, SizeOf (Buffer), Result) Result returns the number of bytes actually written. Result in both BlockRead/write is optional. If you don't specify it, and the number of bytes is not an exact multiple of the record size that you specified in your Reset/Rewrite, you'll get an I/O error. P.S. This is all done from memory, so you should look things up for more specific information on it. //////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ +---------+ Scott Maxell -- Bitnet ->> IO92203 @ maine | | -- Internet ->> IO92203 @ maine.maine.edu | O | | | | "What I need is a computer that will do what I want it to +---------+ do, not what I tell it to do..."