Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!waikato.ac.nz!canterbury!phys169 From: phys169@csc.canterbury.ac.nz Newsgroups: comp.lang.pascal Subject: Re: FILES and pointers Message-ID: <1991Apr22.153127.499@csc.canterbury.ac.nz> Date: 22 Apr 91 03:31:27 GMT References: <1991Apr22.014013.7390@usenet.ins.cwru.edu> Organization: University of Canterbury, Christchurch, New Zealand Lines: 25 In article <1991Apr22.014013.7390@usenet.ins.cwru.edu>, wct@po.CWRU.Edu (William C. Thompson) writes: > > Say I want to save a dynamically sized structure.... > The problem is that I need to save this to disk so that it can > be recalled as quickly as possible. If you use Turbo Pascal, the most efficient method is simply an untyped file, and use blockwrite to output the appropriate number of bytes, e.g. type BufferType = array[1..65520] of byte; var BufferPtr : ^BufferType; MyFyle : file; begin assign(MyFyle,'something'); rewrite(MyFile,1); getmem(BufferPtr,some-number); blockwrite(MyFyle,BufferPtr^,some-number); end. In generic Pascal, you might have to either issue many writes (e.g. FILE OF CHAR) or write too much (e.g. FILE OF BUFFER, where bufferptr was declared as a pointer to type Buffer), it all depends on the implementation's enhancements if you're after efficiency. Hope this helps, Mark Aitchison.