[Development] Changing container privates again

Thiago Macieira thiago.macieira at intel.com
Mon Jun 11 17:24:29 CEST 2012


On segunda-feira, 11 de junho de 2012 16.47.46, João Abecasis wrote:
> The proposed QArrayAllocatedData is 32-bytes in size, but at the cost of two
> 4-byte padding holes. That's not that much different from a 24-byte header
> with no holes -- you can always add padding at the end ;-)
> 
> With a 32-byte default header you get the prepend optimization for free:
> 
>     struct QArrayData
>     {
>         qptrdiff offset;
>         uint size;
> 
>         QtPrivate::RefCount ref;
>         uint flags;
> 
>         uint alloc;
>         qptrdiff beginOffset;
>     };
> 
> 24/32 bytes. (16/24 bytes if we move offset and size out)

beginOffset and offset overload each other. I don't see the need for both. We 
can get rid of one, since they mean the same thing.

If we move offset and size out, then we need to drop to 16 bytes on 64-bit 
systems. It should be only the refcount, flags and alloc (the latter only for 
allocated data).

By moving the alloc out, we also drop the overhead of QStringLiteral to only 2 
ints. And it could go down to one, if we set the immutable header flag in the 
flags too.

> >> Would it be worth to set the minimum alignment for the data as 16-bytes,
> >> at
> >> the expense of padding we explicitly add in QArrayData::allocate? (Since
> >> this decision can be done inside that function it would have no impact on
> >> ABI)
> > 
> > QArrayData::allocate can take that decision. In fact, that was in my plans
> > for some future improvement.
> > 
> > But that means we'll use 32 bytes anyway for all allocations, in any
> > platform.
> The decision can still be made conditional on the architecture or so.

True.

But I can turn around and say that on some architectures we want the header to 
be as small as possible, so we don't want to keep the "alloc" member in static 
allocations.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
     Intel Sweden AB - Registration Number: 556189-6027
     Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120611/bac68195/attachment.sig>


More information about the Development mailing list