[Gambas-user] Code for object serialization

Jussi Lahtinen jussi.lahtinen at ...626...
Sat Feb 23 15:34:00 CET 2013


> Yes, if it hits an object property then set a marker in the file and call
> itself on that object. There is only one problem with this: your code can
> only handle (public) properties. Actually an object serialised by your code
> and then deserialised could stop working properly because Private variables
> not bound to properties (which weren't saved therefore) may not contain the
> right values anymore.
>

You are right.
I didn't think about that, because I wrote this piece of code couple
specific classes in my mind.
So, it's not universal solution.




> I think you can use these to generate a binary dump of an object to a file,
> but the thing is: the backing structures you dump most likely contain
> pointers to other structures (Gambas objects or structures allocated by a
> shared library!) which will become invalid pointers when loaded into
> another
> process.
>

True, that is troublesome to overcome.




> I think the solution to both above problems is already in Settings.Write().
> It is capable of _correctly_ writing and restoring objects if they export a
> Settings property.


Settings property is just pretty limited with it's capabilities when
speaking of serialization,
but of course it's very good for it's intended use.




> As a matter of fact, the object itself only really knows
> what must be serialised and can also provide its private variables.
>
> Alas, I don't see how the serialisation process could be done _without_ the
> object being deeply involved by providing its internal information.
>

I understand your point.
I think the object should be designed to be serialized, or you have to do
it manually.

Now I wonder how Boost library does serialization!


Jussi



More information about the User mailing list