[comp.lang.c++] Storing and reading C++ objects

ward@eplrx7.UUCP (ward) (08/26/89)

Do any of you C++ guru types have suggestions on how to implement
methods to store and read class objects?  Obviously, most cases are easy,
however I want to be able to store a neural network which involves
a lot of objects pointing to other objects.  I have to preserve these
relationships!  If anyone has a nifty way to do this, I'd appreciate
the help.

Thanks in advance.

Rick

-- 
    Rick Ward                         |        E.I. Dupont Co.
    uunet!eplrx7!ward                 |        Engineering Physics Lab
    (302) 695-7395                    |        Wilmington, Delaware 19898
    Just Say When.                    |        Mail Stop: E357-302

dune@cbnewsl.ATT.COM (Greg Pasquariello) (08/28/89)

In article <715@eplrx7.UUCP> ward@eplrx7.UUCP (ward) writes:
:
:Do any of you C++ guru types have suggestions on how to implement
:methods to store and read class objects?  Obviously, most cases are easy,
:however I want to be able to store a neural network which involves
:a lot of objects pointing to other objects.  I have to preserve these
:relationships!  If anyone has a nifty way to do this, I'd appreciate
:the help.
:
:Thanks in advance.
:    Rick Ward                         |        E.I. Dupont Co.

Please post your answers, or Rick, at least summarize.  I have been looking
for an elegant way of doing the same thing for a hyperclass, and so far I
am stumped.

Greg Pasquariello
att!picuxa!gpasq

nusbaum@meson.uucp (R. James Nusbaum) (08/31/89)

In article <1648@cbnewsl.ATT.COM> dune@cbnewsl.ATT.COM (Greg Pasquariello) writes:
>In article <715@eplrx7.UUCP> ward@eplrx7.UUCP (ward) writes:
>:
>:Do any of you C++ guru types have suggestions on how to implement
>:methods to store and read class objects?  Obviously, most cases are easy,
>:however I want to be able to store a neural network which involves
>:a lot of objects pointing to other objects.  I have to preserve these
>:relationships!  If anyone has a nifty way to do this, I'd appreciate
>:the help.
>:
>:Thanks in advance.
>:    Rick Ward                         |        E.I. Dupont Co.
>
>Please post your answers, or Rick, at least summarize.  I have been looking
>for an elegant way of doing the same thing for a hyperclass, and so far I
>am stumped.
>
>Greg Pasquariello
>att!picuxa!gpasq

One way to do 'world dumps' of pointer linked networks involves using
an object heap to store all objects.  In this method objects are
referenced by heap indexes.  The network is then dumped by writing out
the heap and the roots of the network, which are simply indexes.

It is a bit hard to do this in C++, but not impossible.  The first
step is to allocate objects from a separate free store than the
general use one.  This can be accomplished in constructors.  The
allocator must store the type of the object with the object in the
free store for reasons that will become apparent.  This can be done
transparently the same way free list pointers and size information is
stored by most general purpose allocators.

The steps to do the dump are as follows:
1. Compact the free store to remove holes.

2. Convert all object pointers into offsets into the free store.  This
includes the roots of the network and pointers stored inside objects.

3. Dump the free store.

4. Dump the roots of the network.

The steps to do the restore:
1. Load the free store.

2. Load the roots.

3. Convert the roots (still in offset form) into pointers.

4. For each object in the free store (we know the type from the type info)
convert the offsets stored inside object back into pointers.


One way to avoid having type info in the free store is to use a separate
free store for each object type.

Hope this helps.

Jim Nusbaum
Radiation Research Laboratory
Loma Linda University Medical Center
nusbaum%proton.uucp@ucrmath.ucr.edu