By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

mmap for dumping and loading tree

sangeeth
P: 23
I have a n-ary tree in memory.
I want to dump this into a file so that I can read this back into memory at a later time.
I understand that I have to change the pointers in nodes of the trees to offsets(maybe from root).
But can anyone tell me how mmap can be used to reload a Data structure from file to memory.
thanks in advance
Jun 18 '07 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
I would write the key/data values to disc with a field separator. On the playback, you read the key/data values an insert into a new tree in memory.
Jun 18 '07 #2

Expert 10K+
P: 11,448
I have a n-ary tree in memory.
I want to dump this into a file so that I can read this back into memory at a later time.
I understand that I have to change the pointers in nodes of the trees to offsets(maybe from root).
But can anyone tell me how mmap can be used to reload a Data structure from file to memory.
thanks in advance
You're right about the conversion from pointer values to unsigned int values
(given the pointer to the start of the memory block) and you have to do the
reverse when you map that file to memory again. The start of the block is
the new base pointer and you have to convert those unsigned ints back again
to pointer values; it's a process similar to loading a process image; it's quite
low level stuff where every single bit has to be correct. It's a wise thing to build
and keep a table of offsets which ints needs to be converted back again and
save that table to your file too.

kind regards,

Jos
Jun 18 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.