reading and writing a pointer in binary mode.

Started by
0 comments, last by GekkoCube 19 years, 11 months ago
this problem came up while trying to save and load some engine related data to disk. in my engine i have a list of Entity pointers, each pointer pointing to memory for the entity, of course. is there an elegant way to dump/read the entire Entity object to/from disk? or am i stuck to writing/reading each sub-component of entity to disk?
Advertisement
My favorite way to do stuff like this is to store all of you''re entities in a block of contiguous memory... If you''re entities point to eachother, don''t store ABSOLUTE pointers, store offsets from the beginning of the buffer... And likewise, when you want to use entities, don''t use absolute pointers... Store and offset from the beginning of the buffer...

Now, you can read and write the whole buffer to disk... and the code (since all of the pointers are relative), will work...

I thought of this technique when I had to store and then be able to read from disk a whole n-ary tree....

Tony

This topic is closed to new replies.

Advertisement