View Full Version : Saving complex data structures to disk
06-23-2006, 11:35 AM
I would like to write a complex data structure (an object containing arrays of other objects) to disk. Unfortunately, file_put_contents() only accepts strings and arrays, so I can't use that.
Does anybody know of a general purpose script which could accomplish this? Alternatively, does anybody know where I could look for one?
Thanks very much.
06-23-2006, 12:00 PM
I think I've answered my own question. If I recursively cast each object as an array then I turn the entire structure into a an array...
why not serialize them before writing them to the file/db, and then unserialize them after you read them from the file/db ?
06-23-2006, 12:29 PM
Cool. I only thought serialize worked for arrays. This is just what I was looking for , thanks.
06-23-2006, 04:54 PM
Is there not a binary equivalent of serialize? Parsing/unparsing a big text file (mine is over 100k) looks quite expensive. Surely a structure could just be dumped from memory onto disk and then reloaded again, much like a binary swap file...
not sure what you are talking about.
arrays and objects are 'in memory constructs' and serializing them is the most efficient way to get a storable representation of them. when you unserialize them, you immeadeately get an in memory construct. i don't realy understand what extra you can wish for.
06-26-2006, 07:42 AM
I'm just pointing out that, in theory, it should be possible to dump the structure directly from memory to disk (without going through the process of serializing). This assumes that (i) the data structure occupies contiguous memory, (ii) there are no absolute references within the binary memory block.
Basically, the only thing you could do with such a file is it load it back into memory - but thats all I'd want to do anyway.
It was just a curiosity, serialize is working fine for me. I just have a feeling that the process could be speeded up...
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.