becker@uiucdcsb.UUCP (11/04/84)
i was wondering if any of you C hackers out there might be able to help me on this: i have a program that generates a rather complex model of an object (this is for computer graphics) that is composed of records. each record contains data and pointers to other records. this entire data structure is irregular. how can i save this structure in a file so that it can be used by another program? keep in mind that this structure is not tree-like in any way; it more closely resembles something a spider did under influence of drugs. thanks, craig becker uiucdcs!uiucdcsb!becker
gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (11/07/84)
> i have a program that generates a rather complex model of an object > (this is for computer graphics) that is composed of records. each record > contains data and pointers to other records. this entire data structure > is irregular. how can i save this structure in a file so that it can > be used by another program? keep in mind that this structure is not > tree-like in any way; it more closely resembles something a spider did > under influence of drugs. It would be hard to make sense of the (data address space) pointers in any other process image; otherwise you could just do a raw dump of your heap space. If there is some canonical way of traversing your structure (too bad it's not a tree), then you could do that and replace pointers by directory indices while writing out the data plus the directory. Reading it back in would be the converse. This is the sort of thing that needs to be designed up front before it's too late..
stern@inmet.UUCP (11/09/84)
I would say your best bet is to use fread(3) and fwrite(3) to make an non-ascii file of data structures. This will help you save the data part (i.e. the non-pointer data) somewhere neatly. However, you have to remember that if you stow some data in a file, and then load it up again in another program, it may reside in a different place in memory, and therefore your pointers will be different. Maybe a better idea is to put all of the data structures into an array, replacing the pointers with integer array indices. It is easy enough then to rebuild your structures after reading the arrays out of a file using fread. --Hal Stern {ihnp4, harpo, esquire, ima}!inmet!stern