Archived

This topic is now archived and is closed to further replies.

zorlack

save pointers on disk

Recommended Posts

Why would you want to? A pointer points to a location in memory, therefore once your program is unloaded from memory and restarted, the location the pointer was pointing to would have changed.

Now if you want to save the data that the pointer points to, yes you can using your file I/O method of choice be it streams, or older fwrite. If you need an example just ask.

~ Chris

Share this post


Link to post
Share on other sites
Pointer as in *p? Tis better to save the data, *p could be a different number next time program is run. If you''re sharing the data between two or more apps and the memory is out there then I''m not sure.. the nature of multitasking, I wonder if the memory from one program will go to swapfile or something and the active program might not see what memory the pointer is pointing to..

I fseek, therefore I fam.

Share this post


Link to post
Share on other sites
Eh. Well theres no real way to save the pointers. What you have to do is either save the data thats in the tree to disk, and recreate the tree when your application runs, or you have to make up some sort of a file format, that stores the relationship between nodes in the tree.

~ Chris

[edited by - evilvodkaman on September 2, 2003 12:29:48 AM]

Share this post


Link to post
Share on other sites
I get the impression that the OP is not really ready to be making trees and other things with pointers, without understanding how they are stored. Personally, I would search the forum for some more information on pointers before moving on. There are an awful lot of threads about pointers.

Share this post


Link to post
Share on other sites
I suggest you convert the pointer to an integer value (unsigned long) and use that as an id for the data each node contains. You will also need to do the same for node pointers.

When you save, write each object id followed by the object data. Then, loop through the tree again. THis time, for each node you write the node id followed by the ids of any nodes this one points to and the id of the object it contains. When you load, use the ids to match nodes with object data. Now your pointers have new addresses but the tree retains the same structure. You can do it all in one loop if you flag each object when it is saved.

Share this post


Link to post
Share on other sites
saving a pointer seems strange. you would want to do this why? a pointer is just a reference to memory, which if loaded, would have to reload the actual data. So you should save the data, and make a pointer to it

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you got Game Programming Gems 1 lying around, read the parts about HANDLEs (You could try searching online too)

If you dont have it, you might consider buying it, i found it to be quite good

It covers some not so easy topics tho, so if you dont understand how pointers work you should first work on the basics.
(www.gametutorials.com explains most C++ features quite well iirc)

Share this post


Link to post
Share on other sites