Il 28/04/20 21:45, Matthew Woehlke ha scritto:
* QList gets adapted so that its internal array allocates 3 * sizeof(void*) per element, so that e.g. Q6StringList won't require a per-item allocation. This would then also avoid allocations for other datatypes, e.g. QStringView, QImage, maybe QVariant and QColor; but of course waste a ton of space for the ones which remain small (most of Qt implicitly shared datatypes).Uh... can't it allocate sizeof(T) if T meets some criteria? IOW, I don't see the second case penalizing smaller types unless the implementation is poorly done.
This way of working is the *key* of QList design. QList is always a vector of void* (so it's nice for Qt pimpled types). This allows to type erase the entire management of the vector (it's always a vector of void*), reducing the amount of template code that needs to be instantiated.
The only type specific operations are setting/retrieving/deleting a value in that vector, thus giving us the rule:
- if the type is small and relocatable, just put it in the vector - otherwise, heap allocate and put the pointer in the vectorThere are no exceptions (which is why e.g. Q5List<int> on 32 bits is wasteful), again by design. And, because noone is volunteering to do the work while QVector is already there...
My 2 c, -- Giuseppe D'Angelo | [email protected] | Senior Software Engineer KDAB (France) S.A.S., a KDAB Group company Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com KDAB - The Qt, C++ and OpenGL Experts
smime.p7s
Description: Firma crittografica S/MIME
_______________________________________________ Development mailing list [email protected] https://lists.qt-project.org/listinfo/development
