[Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO
Thiago Macieira
thiago.macieira at intel.com
Wed Jul 22 16:52:17 CEST 2015
On Wednesday 22 July 2015 10:25:02 abbapoh at gmail.com wrote:
> By the way, is it possible to add custom allocators to the vector? As we
> have to store reference counter (at least) with the data, wouldn't there be
> problems with aligning of the memory?
Allocators is a feature we've never supported and I don't see us supporting.
I don't see a problem with the alignment. QArrayData is allocated with
alignment of min(alignof(QArrayData), alignof(T)), then we find the proper
alignment for T inside the buffer and that should be enough.
>From qarraydata.cpp:
// Allocate extra (alignment - Q_ALIGNOF(QArrayData)) padding bytes so we
// can properly align the data array. This assumes malloc is able to
// provide appropriate alignment for the header -- as it should!
// Padding is skipped when allocating a header for RawData.
if (!(options & RawData))
headerSize += (alignment - Q_ALIGNOF(QArrayData));
[...]
quintptr data = (quintptr(header) + sizeof(QArrayData) + alignment -
1)
& ~(alignment - 1);
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Development
mailing list