[Qt-interest] On overriding qMalloc in QVector

Benoit Jacob jacob.benoit.1 at gmail.com
Thu Oct 22 21:49:25 CEST 2009


2009/10/22 Thiago Macieira <thiago at kde.org>:
> Em Quinta-feira 22 Outubro 2009, às 20:01:29, você escreveu:
>> > I managed to get an aligned QVector data, but the change is not data-
>> > compatible.
>>
>> ah ok.
>>
>> > If I put this change in Qt 4.6, then we could have newly-compiled code
>> > allocating aligned buffers passing a QVector to code that wasn't
>> > recompiled. If that older code tried to free the vector, the application
>> > would most likely crash.
>> >
>> > I think I can safely make the change for QMap and QHash though. QList
>> > isn't affected by this issue, while QLinkedList cannot be solved properly
>> > (it uses new on QLinkedListNode<T>).
>>
>> hm, since this can't be done for QVector, i'd say don't bother. it
>> would only make things more complicated.
>>
>
> After a bit more of experimentation, I think it can be done.
>
> I'm just using a bit of heuristics: if the type alignment is less than a
> certain threshold, continue using qMalloc and qFree. Otherwise, use the
> aligned functions. The idea is that, if the alignment requirement was higher
> than what qMalloc returned, then no one was using QVector with that type.

Sure that logic seems correct, but i don't understand, how do you get
the type alignment? Some compiler extensions? The alignof keyword is
only coming in c++1x...

Benoit




More information about the Qt-interest-old mailing list