Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!chaph.usc.edu!aludra.usc.edu From: ajayshah@aludra.usc.edu (Ajay Shah) Newsgroups: comp.lang.pascal Subject: Re: I/O with complex datastructures Keywords: I/O datastructures save Message-ID: <11274@chaph.usc.edu> Date: 6 Aug 90 20:45:39 GMT References: <140232@sun.Eng.Sun.COM> Sender: news@chaph.usc.edu Organization: University of Southern California, Los Angeles, CA Lines: 37 Nntp-Posting-Host: aludra.usc.edu In article <140232@sun.Eng.Sun.COM> jasonf@cetemp.Eng.Sun.COM (Jason Freund) writes: > > I've never dealt with file I/O in Pascal and I have a question >about saving a complex datastructure. Basically, I have a single, very >complex datastructure that holds just about all of the information in my >program. I want to save all of its data into a file so that I can load >it back up when the program's user wants to change some info in the database. --------------------------------------------------------------------------- type anytype = blahblahblah procedure savetodisk(fn:fnstring; var r:anytype); {var for speed} var f: file of anytype; begin assign(f, fn); rewrite(f); write(f, r); close(f) end; --------------------------------------------------------------------------- Strengths: speed; it's very, very fast. Caveat: you have to thread through complex pointer-oriented data-structures "by hand" and then you could easily hit trouble since TPascal isn't good at handling files containing hetrogenous objects. Amazingly, the best solution in that case is TP 5.5's object-oriented implementation of a stream concept. It's very beautifully done, and is a pleasure to use. Minor point: you could lookup sizeof(r) to know how big the file is going to be. -- _______________________________________________________________________________ Ajay Shah, (213)747-9991, ajayshah@usc.edu The more things change, the more they stay insane. _______________________________________________________________________________