How to store data intelligently?

    cniehaus's picture
    2003
    13
    Oct

    I have been thinking about how to store the data in Kalzium (chemistryapp in kdeedu). Currently I have a class called kalzium in which 110 "elements" are. An "element" is of course an object which stores the data available for one of the 110 elements in the periodic table.

    I give a pointer of the kalzium-object to every object I create, and which needs the data. For KDE 3.3/4 I would like to restructure a lot in Kalzium. So my question is: what is the best way to store my data. Of course the data doesn't change. The user can't add any data. So I could use a global

    static const QValueList<Element*>

    but I am not sure if that is good. Is it better to give a pointer to all created objects? Or is there even a third way which is the best solution

    Comments

    Comment viewing options

    Select your preferred way to display the comments and click "Save settings" to activate your changes.
    krake's picture

    Vector vs List

    If the number of elements does not change and you do not need list behaviour (inserting, removing in the middle), you should consider using a vector (QPtrVector, QValueVector).

    Accessing elements by index will be more effective: O(1) instead of O(n)

    jason harris's picture

    In KStars, we simply use a QP

    In KStars, we simply use a QPtrList for each catalog of objects. So we have a starList containing pointers to our 126,000 StarObjects, a deepSkyList containing pointers to our 14,000 DeepSkyObjects, etc.
    I guess you'd need only one QPtrList for kalzium.

    What's the practical difference between "QPtrList<Element>" and "QValueList<Element*>"?

    Anyway, the QPtrLists seem to work fine for us, but I would of course be interested to hear about a better way as well.

    Jason
    --
    KStars: A desktop planetarium for KDE

    cornelius schumacher's picture

    Singleton

    What about making the kalzium class a Singleton?

    cniehaus's picture

    Re: Singleton

    Yes, that could also work. Ok, not kalzium but a class wich includes the data and some methods to access it, of course. Even though I don't see to much of a difference between a singleton and a global static object.

    Comment viewing options

    Select your preferred way to display the comments and click "Save settings" to activate your changes.