What is equivalent to std :: deque in Qt?

I use a few lines of code from a Qt project to add to Qvector every 1s. I noticed that in STL, deque may have better performance when adding a new element to the end of this vector. What is the equivalent or similar way to Qt? Reason: I did not find in Qt libraries.

Julio

+4
source share
2 answers

There is no direct equivalent in QT to the std::deque class.

However, it is best to use a QList .

Here's what the documentation on QT container classes says:

For most purposes, QList is a suitable class. Its index-based API is more convenient than the QLinkedList iterator-based API, and it is usually faster than QVector because of the way it stores its elements in memory. It also expands to less code in your executable.

In any case, if you only add items once per second, there will not be much influence on the selection of one of them.

+4
source

There is no need to have a Qt equivalent for each std container, you can use std :: deque if that is what you need.

In any case, note that for the case when you make many inserts at the end of the vector, std :: vector and QVector have a member function called reserve (see links), which can be used to preallocate a larger buffer and speed up insertion in the end.

+1
source

Source: https://habr.com/ru/post/1480651/


All Articles