Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Serialize Linked List

Serialize Linked List

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiondata-structures
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Esaias Pech
    wrote on last edited by
    #1

    I made a list of points:

    class CPuntoList : public CObject
    {

    public:
    CPunto* raiz;
    CPuntoList();
    void Inserta(CPunto* nodo);
    virtual ~CPuntoList();
    virtual void Serialize(CArchive &ar);
    long getSize();
    }

    The serialize function of the List looks like this:

    void CPuntoList::Serialize(CArchive &ar)
    {
    CObject::Serialize(ar);
    long i;
    if(ar.IsStoring())
    {
    ar<<raiz;
    }
    else
    {
    ar>>raiz;
    }
    }

    the Punto Class looks like this:

    class CPunto : public CObject
    {
    public:
    CPunto();
    CPunto(double _x, double _y, double _z, double _zTn);
    CPunto *m_pSigPunto; // Pointer to the next point
    CGLColor *m_pColor;
    void Inicializa();
    virtual ~CPunto();
    virtual void Serialize(CArchive& ar);
    public:
    double x, y, z, zTn;
    private:
    DECLARE_SERIAL(CPunto)
    };

    Serialize functino looks like this:

    void CPunto::Serialize(CArchive &ar)
    {
    CString str;

    if(ar.IsStoring())
    {
    	ar<<x;
    	ar<<y;
    	ar<<z;
    	ar<<zTn;
    	ar<<m\_pColor;
    	ar<<m\_pSigPunto;	//	Pointer to next point (Linked list)
    }
    else
    {
    	ar>>x;
    	ar>>y;
    	ar>>z;
    	ar>>zTn;
    	ar>>m\_pColor;
    	ar>>m\_pSigPunto;	//	Pointer to next point (Linked list)
    }	
    

    }

    Now the question is: When I load about 200 points to the list or even 5,000 points and I save the data to a file using the serialize functions everything works fine, both the storing and the loading. But when I try to save about 12,000 points, there is an error in both storing and loading, it says "Stack overflow." I think because from one function (the serialize function) I call the a serialize function over and over so the Stack overflows... Is that the problem? or what could be the issue? anyways, more importantly, how can I solve it?? Please help!!!!

    K K 2 Replies Last reply
    0
    • E Esaias Pech

      I made a list of points:

      class CPuntoList : public CObject
      {

      public:
      CPunto* raiz;
      CPuntoList();
      void Inserta(CPunto* nodo);
      virtual ~CPuntoList();
      virtual void Serialize(CArchive &ar);
      long getSize();
      }

      The serialize function of the List looks like this:

      void CPuntoList::Serialize(CArchive &ar)
      {
      CObject::Serialize(ar);
      long i;
      if(ar.IsStoring())
      {
      ar<<raiz;
      }
      else
      {
      ar>>raiz;
      }
      }

      the Punto Class looks like this:

      class CPunto : public CObject
      {
      public:
      CPunto();
      CPunto(double _x, double _y, double _z, double _zTn);
      CPunto *m_pSigPunto; // Pointer to the next point
      CGLColor *m_pColor;
      void Inicializa();
      virtual ~CPunto();
      virtual void Serialize(CArchive& ar);
      public:
      double x, y, z, zTn;
      private:
      DECLARE_SERIAL(CPunto)
      };

      Serialize functino looks like this:

      void CPunto::Serialize(CArchive &ar)
      {
      CString str;

      if(ar.IsStoring())
      {
      	ar<<x;
      	ar<<y;
      	ar<<z;
      	ar<<zTn;
      	ar<<m\_pColor;
      	ar<<m\_pSigPunto;	//	Pointer to next point (Linked list)
      }
      else
      {
      	ar>>x;
      	ar>>y;
      	ar>>z;
      	ar>>zTn;
      	ar>>m\_pColor;
      	ar>>m\_pSigPunto;	//	Pointer to next point (Linked list)
      }	
      

      }

      Now the question is: When I load about 200 points to the list or even 5,000 points and I save the data to a file using the serialize functions everything works fine, both the storing and the loading. But when I try to save about 12,000 points, there is an error in both storing and loading, it says "Stack overflow." I think because from one function (the serialize function) I call the a serialize function over and over so the Stack overflows... Is that the problem? or what could be the issue? anyways, more importantly, how can I solve it?? Please help!!!!

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      you are right calling so often the stack is a problem. Somehow is it possible to enhance the stack. But it is bad style. (if you call a lot more you run in the same trouble) You better Serialize the points one ofter the other. The linked list stays otuside the serialization.

      Press F1 for help or google it. Greetings from Germany

      1 Reply Last reply
      0
      • E Esaias Pech

        I made a list of points:

        class CPuntoList : public CObject
        {

        public:
        CPunto* raiz;
        CPuntoList();
        void Inserta(CPunto* nodo);
        virtual ~CPuntoList();
        virtual void Serialize(CArchive &ar);
        long getSize();
        }

        The serialize function of the List looks like this:

        void CPuntoList::Serialize(CArchive &ar)
        {
        CObject::Serialize(ar);
        long i;
        if(ar.IsStoring())
        {
        ar<<raiz;
        }
        else
        {
        ar>>raiz;
        }
        }

        the Punto Class looks like this:

        class CPunto : public CObject
        {
        public:
        CPunto();
        CPunto(double _x, double _y, double _z, double _zTn);
        CPunto *m_pSigPunto; // Pointer to the next point
        CGLColor *m_pColor;
        void Inicializa();
        virtual ~CPunto();
        virtual void Serialize(CArchive& ar);
        public:
        double x, y, z, zTn;
        private:
        DECLARE_SERIAL(CPunto)
        };

        Serialize functino looks like this:

        void CPunto::Serialize(CArchive &ar)
        {
        CString str;

        if(ar.IsStoring())
        {
        	ar<<x;
        	ar<<y;
        	ar<<z;
        	ar<<zTn;
        	ar<<m\_pColor;
        	ar<<m\_pSigPunto;	//	Pointer to next point (Linked list)
        }
        else
        {
        	ar>>x;
        	ar>>y;
        	ar>>z;
        	ar>>zTn;
        	ar>>m\_pColor;
        	ar>>m\_pSigPunto;	//	Pointer to next point (Linked list)
        }	
        

        }

        Now the question is: When I load about 200 points to the list or even 5,000 points and I save the data to a file using the serialize functions everything works fine, both the storing and the loading. But when I try to save about 12,000 points, there is an error in both storing and loading, it says "Stack overflow." I think because from one function (the serialize function) I call the a serialize function over and over so the Stack overflows... Is that the problem? or what could be the issue? anyways, more importantly, how can I solve it?? Please help!!!!

        K Offline
        K Offline
        killabyte
        wrote on last edited by
        #3

        sounds like your loading ar with to much info to write at once, try writing chunks when ar reachs a set size then clear ar repeat, until all data is written

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups