Serialization Question(s) - Programmer

This is a discussion on Serialization Question(s) - Programmer ; Hi: I'm trying serialization for the first time. I have some lists, some quite large, and I get a 'stack overflow' which I assume is due to recursively calling serialize when I try to insert (' (points to the next ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Serialization Question(s)

  1. Serialization Question(s)

    Hi:

    I'm trying serialization for the first time. I have some lists, some
    quite large, and I get a 'stack overflow' which I assume is due to
    recursively calling serialize when I try to insert ('<<') the 'next'
    (points to the next in the list) pointer. I could not insert the 'next'
    pointer and, when loading, use the actual address of the next record
    extracted. This seems sort of inelegant and I'm wondering if the authors
    of CArchive et. al. had something else in mind to solve this problem


  2. Re: Serialization Question(s)

    Donald Becknell wrote:

    > Hi:
    >
    > I'm trying serialization for the first time. I have some lists, some
    > quite large, and I get a 'stack overflow' which I assume is due to
    > recursively calling serialize when I try to insert ('<<') the 'next'
    > (points to the next in the list) pointer. I could not insert the 'next'
    > pointer and, when loading, use the actual address of the next record
    > extracted. This seems sort of inelegant and I'm wondering if the authors
    > of CArchive et. al. had something else in mind to solve this problem
    >


    Are you trying to store the pointer? Don't do that - pointers are not
    usable when the file is read. Serialize the object pointed to, not the
    pointer.

    --
    Scott McPhillips [VC++ MVP]


  3. Re: Serialization Question(s)

    Somehow I thought that the whole purpose of serialization was to
    'manage' pointers in persistent storage. Maybe I'm not being clear:

    class Foo : public CObject {

    Foo * next;

  4. Re: Serialization Question(s)

    Donald Becknell wrote:
    > Somehow I thought that the whole purpose of serialization was to
    > 'manage' pointers in persistent storage. Maybe I'm not being clear:
    >
    > class Foo : public CObject {
    >
    > Foo * next;
    > .
    > Foo(): next(NULL) { /* other constuctor activities */
    > };
    > void Serialize(CArchive &arc) {
    > if (arc.IsStoring()) {
    > arc << next;
    > .
    > .
    > }
    > else {
    > arc >> next;
    > .
    > .
    > }
    > }
    > Foo *headOfList=new Foo;
    > /* Code to make a list of some 6,000 of Foo. */
    > // Finally, after creating the archive.
    > archive << headOfList;


    No, the purpose of serialization is to let objects serialize themselves.
    Step throught the serialization in the SCRIBBLE tutorial - I think it
    does exactly what you are trying to do.

    --
    Scott McPhillips [VC++ MVP]


+ Reply to Thread