mardi 24 mars 2015

Is storing data directly in a list node better than storing a pointer to data?


Suppose we have two different doubly-linked list structures:




  1. One has content of the node embedded directly in the node:



    struct Content {
    // some stuff
    };
    struct Node {
    struct Node *next;
    struct Node *prev;
    struct Content content;
    }



  2. The other has a pointer to content:



    struct Content;
    struct Node {
    struct Node *next;
    struct Node *prev;
    struct Content *content;
    }



What are considerations to prefer one option to the other? The points can be about everything: performance in different conditions, architecture, ease of modification, ease of manipulating the list, etc.


I'd like to gather knowledge about the trade-offs present.


Shown code is C, but the question also applies to C++, or any other language which has explicit pointers.





Aucun commentaire:

Enregistrer un commentaire