QList difference and the like containers :( turn QVector)

Source Address: https://blog.csdn.net/qq_33266987/article/details/53333373

Qlist, QVector the list, vector seems less similar ;

list insertion and deletion quickly, vector inquiry soon.

QList but is based on its index tag stored in the memory element items ( though memory is not continuous , and this list is the same), but using [] operator, may also be used .at () operation.

QVector difference QList and other containers of:

1, in most cases you can use QList. Like The prepend () and insert () this operation, more typically faster than QList QVector. This is because the index is based on QList tag stores its elements item in memory, than the kind of dependence iterator iterations more quickly. And your code is also less.

2, if you need to list a real connection with, and the need to ensure a fixed insert time-consuming. Then use iterators instead of labels. Use QLinkedList ();

3, if you need to open up contiguous memory storage space, or your element than a big pointer, then you need to avoid individual insert operation, stack overflow, this time with QVector

4, if you need a variable number of low-level array size, with QVarLengthArray enough. He can be pre-allocated array of known length of the size of the stack, if it exceeds this length, will continue to be stored on the heap. The default size of 256

Guess you like

Origin www.cnblogs.com/Stephen-Qin/p/11537390.html