#135 Avoid circular references on Slots

closed-fixed
None
5
2002-05-31
2002-05-17
No

Imagine that A contains B, that B contains C, and now
place a new link: C contains A.
The system is now fucked and you can't save the file
to disk because of a recursion problem.

Discussion

  • Robert Wallis

    Robert Wallis - 2002-05-20

    Logged In: YES
    user_id=548644

    What if during serialization you flag objects that have
    been saved? You could do this two ways I can think of off
    the top of my head. Using a serialized variable in the
    Object it self, or a list of objects that have been saved.
    The problem with the list idea is it might take a while to
    search for each object during a save. And the problem with
    a "serialized" variable, is that it takes up memory.

    However you can use the bit-field extention to make sure
    that a boolean value only takes 1 bit instead of a whole
    byte (or even a dword in Microsoft).

    I haven't looked at the Arianne source, but...

    struct Object{
    bool serialized : 1; /* has this object been saved
    already? */
    [...]
    };

    struct Container{
    Object** items; /* an array of pointers */
    unsigned int items_total;
    };

    /* save container and all items within */
    SerializeContainer(Container* box){
    int i;
    for(i=0; i<box->items_total; i++){
    SerializeObject(box->items[i]);
    }
    }

    /* save item */
    SerializeObject(Object* obj){
    if(!obj->serialized){
    SaveIt(obj);
    obj->serialized=true;
    }
    }

    - Robert

     
  • Miguel Angel Blanch Lardin

    • priority: 9 --> 5
    • status: open --> closed-fixed
     

Anonymous
Anonymous

Cancel  Add attachments