c++ - Most efficient way to store a mixed collection of doubles and ints -


I need to store ints and a couple of doubles (representing nominal and actual valuable data) in C ++. I have to explicitly assign them all to std :: vector & lt; Double & gt; I can store in , but it feels a bit wrong and does not get aesthetics bonus points.

I could have cooked up something based on polymorphism, but I need to make the collection really efficient: collecting and retrieving the data in the archive should be as fast as possible. I find it difficult to decide whether such a solution would be more efficient.

I have also come to know, which can be of help here.

Additional information: The number of objects in the collection

Briefly: I can clearly explain it in countless ways, but I'm not sure what a good solution would be when ( I) Efficiency is really important and (ii) I also want to write some good code. What is my best bet here?

Edit, additional information: The collection represents a 'row' in a large data set; its elements represent the values ​​of some 'columns'. The qualities of the rows are known, so it is known about which type of data is stored in 'efficiency', I am talking about mainly getting the int / double value of a certain column But the fast setting of values ​​is also important. I have some functions that work on data that need to be retrieved as fast as possible. Example:

  typed characters std :: vector & lt; Double & gt; Line; Zero DoubleFin (Line Combination and Line) {// Function knows that there is always a double on the index double double value = line [0]; ...} zero integerFun (line const & amp; line) {// function knows that index 1 int value is always an integer on line [1]; ...}  

After reading some more ideas and suggestions, it seems that storing int columns and double columns in just two different vectors is a solid solution. After that, the archive line can then define two different members to get nominal and actual data that can use the function.

Just a vector & lt; Double & gt; Okay, I think too, but it depends on how rapid the conversion between the double and the int is (which is probably very impressive).

Sorry to be a bit unclear in the past, I hope it is clear and now that I can think more about this matter.

Is your commanding an important point in the container?

If it is not:

  class MyContainer {std :: vector & lt; Double & gt; Doubles; Std :: vector & lt; Integer & gt; Ints; Push (double value) {couple pish_back (value); } Push (int value) {ints.push_back (value); } ....};  

The iterator part (to browse the entire container) can be a little tricky ...


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -