上QQ阅读APP看书,第一时间看更新
QVarLengthArray
This is another container with attitude—it is not implicitly shared. It preallocates memory for a certain number of elements specified in its template argument, by default 256. If then more space is needed, the container allocates a new buffer dynamically and uses it thereafter.
Keen readers will notice that QVarLengthArray implements the small vector optimization we already discussed. This optimization can be extremely useful when we know in advance that in common cases, the size of a container will not exceed a certain number of objects.