QByteArray 和 QList<unsigned char> 或 QVector<unsigned char> 有什么区别?

What is the difference between QByteArray and QList<unsigned char> or QVector<unsigned char>?

QByteArray 保存单独的字节,如果我们创建 unsigned charsQList,它也将保存单独的字节。

为什么QByteArray存在可以做QList<unsigned char>
QByteArrayQList<unsigned char>QVector<unsigned char> 有什么区别?

我错过了什么要点?

QList 在堆上分配内存并且不保证任何数据局部性,因此使用 QListQByteArray.

之间可能存在性能差异

发件人:http://doc.qt.io/qt-5/qlist.html#details

QVector should be your default first choice. QVector will usually give better performance than QList, because QVector always stores its items sequentially in memory, where QList 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.

QByteArray 还提供了处理字节(和一般字符串)的便捷方法。

QByteArraychar* 的有用包装器。适用于流式处理QDataStream、字符串操作等数据管理。 从文档中您还可以找到:

Behind the scenes, it always ensures that the data is followed by a '[=15=]' terminator, and uses implicit sharing (copy-on-write) to reduce memory usage and avoid needless copying of data.

QList,起初在内存中不是线性的(后续)(你应该使用QVector),并且没有这样有用的API