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
- cniehaus's blog
- Login or register to post comments
- 1240 reads

Comments
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)
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
Singleton
What about making the kalzium class a Singleton?
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.