# Thread: Right storage QGenericMatrix in QList or QQLinkedList or in an best container?

1. Beginner
Join Date
Mar 2018
Posts
13
Thanks
11
Qt products
Platforms

## Right storage QGenericMatrix in QList or QQLinkedList or in an best container?

I have to store data in a several QGenericMatrix<4,4,float> (or in a matrixNxN dimension) like this:
#
QList< QGenericMatrix<4,4,float> > list_matrix_trasf;
QGenericMatrix<4,4,float> empty_matrix;

for (int i=0; i<4; i++){
for (int j=0; j<4; j++){
empty_matrix(i,j) = 0.0;
}
}

int num_storage = 10;

for (int i=0; i<num_storage; i++){
list_matrix_trasf.push_back(empty_matrix);
}

.. charge the right data in matrix .. doing calculus like this ..

QGenericMatrix<4,4,float> goal_matrix;
QGenericMatrix<1,4,float> goal_vector;
QGenericMatrix<1,4,float> test;
test(0,0) = 1.0; // Coord. X
test(1,0) = 0.0; // Coord. Y
test(2,0) = 0.0; // Coord. Z
test(3,0) = 1.0; // never mind

goal_matrix = list_matrix_trasf[1]*list_matrix_trasf[0];
.. or ..
goal_matrix = list_matrix_trasf[3]-list_matrix_trasf[2];
.. and so on ..

goal_vector = goal_matrix * test_vector
#

I need to access to the data in writing and read mode quickly and more often (read data from file and storage it in a matrix_4x4 or in a matrix_NxN dimension), to do matrix calculus in different way, view result data if request in a 3D space.

my question is Qlist is the right contenitor do the job, or an other container classes is better,or i have to do it in a different way?

Join Date
Jul 2008
Posts
447
Thanks
9
Thanked 58 Times in 56 Posts
Qt products
Platforms

## Re: Right storage QGenericMatrix in QList or QQLinkedList or in an best container?

Hi, the Qt docs state the following:
QVector should be your default first choice. QVector<T> will usually give better performance than QList<T>, because QVector<T> always stores its items sequentially in memory, where QList<T> will allocate its items on the heap unless sizeof(T) <= sizeof(void*) and T has been declared to be either a Q_MOVABLE_TYPE or a Q_PRIMITIVE_TYPE using Q_DECLARE_TYPEINFO. See the Pros and Cons of Using QList for an explanation.
However, QList is used throughout the Qt APIs for passing parameters and for returning values. Use QList to interface with those APIs.
If you need a real linked list, which guarantees constant time insertions mid-list and uses iterators to items rather than indexes, use QLinkedList.
Quoted from https://doc.qt.io/qt-5/qvector.html#details

Ginsengelf

edit: additionally I don't think that the container will have an impact that is large enough to see if you do complex matrix calculations.

3. ## The following user says thank you to Ginsengelf for this useful post:

andreaQt (30th July 2020)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.