[Qt-interest] On overriding qMalloc in QVector

Thiago Macieira thiago at kde.org
Thu Oct 22 21:43:32 CEST 2009


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.

I'm working out the kinks of the patch now.
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091022/fda1bbe5/attachment.bin 


More information about the Qt-interest-old mailing list