Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!uc!uh.msc.umn.edu!souka From: souka@uh.msc.umn.edu (Omar Souka) Newsgroups: comp.sys.mac.programmer Subject: Re: Resource Fork data storage--related question Message-ID: <2172@uc.msc.umn.edu> Date: 19 Jul 90 20:05:32 GMT References: <1990Jul17.172044.20361@Neon.Stanford.EDU> <1715MAYER-A@RICEVM1> Sender: news@uc.msc.umn.edu Reply-To: souka@msc.edu Distribution: na Organization: Minnesota Supercomputer Center Lines: 60 > WELL, > > I have a related question. It may be more of a Pascal question than a > Macintosh question, though. I would like to retrieve the contents > of a (rather long) array. A resource of my own type seems > like a logical structure for this. > > I know how to load a resource into memory, but I don't see how then to > store the contents into an array I've declared... > > I would appreciate any suggestions or better ideas. Thanks! > > --David The resource fork is a great place to store nearly any type of data. Here is a sketch of what many programs do. 1. Create a new resource in Resedit. It doesn't have to have anything in it right now but a name (try to make the name unique) and a resource number. Writing to the resource. 1. Call GetResource to get a handle to your resource. 2. If its the first time that your writing to it, you must call SizeHandle to increase the size of the handle to the size of whatever you are going to store. 3. Then simply BlockMove the contents of your data structure into the resource. In C, it would look something like this: BlockMove(array,*ResourceHandle,number_of_bytes); or generically BlockMove(source pointer, destination pointer, # of bytes) This operation will stick the raw bytes of your array into your resource. 4. Call ChangedResource 5. Call WriteResource Reading from the resource 1. Call GetResource 2. If you need to know how big the handle is call HandleSize 3. BlockMove from the resource into your array BlockMove(*ResourceHandle,array,number_of_bytes); In Pascal it would look something like this (just a guess, I don't do Pascal) BlockMove(ResourceHandle^,@array,number_of_bytes) What's great about this technique is that you can store very complicated data structures this way and not really worry about what the structure looks like. If anyone is interested in seeing some actual source, just E-Mail me.