[Development] QProperty and library coding guide

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Fri Jul 17 18:56:39 CEST 2020


Il 17/07/20 17:30, Thiago Macieira ha scritto:
> I will give a +2 for this patch, since I prefer it. That means adding
> properties doesn't imply an extra 8 bytes per class in the hierarchy. Imagine
> a user class hierarcy like QSctpSocket -> QTcpSocket -> QAbstractSocket ->
> QIODevice -> QObject. If each class has properties, that adds 40 bytes to the
> full size of QSctpSocket.
> 
> [Yes, I know Qt-based classes should just put their properties in the d
> pointer, but users don't usually have d pointers]

Even with d pointers, how is that supposed to work? You still need the 
dummy "property object" in the class where it's declared, right? That 
would still add 1 byte to the class, although that can be folded into 
the alignment.

What am I missing here?
> 
> class QObject {
>   QObjectPrivate *d_ptr;
> public:
>   virtual ~QObject();
>   union {
>     P1 objectName;
>     P2 somethingElse;
>   };
> };
> 
> /* alignof == 8, sizeof == 24 
>    (8 vptr + 8 d_ptr + 1 union + 7 padding) */
> 
> class QWidget : public QObject /*, QPaintDevice, I know */
> {
> public:
>   union {
>     P3 visible;
>     P4 geometry;
>   };
> };
> 
> /* alignof == 8, sizeof still 24
>    (23 for the base class + 1 union + 6 padding) */


So in your example QSctpSocket would still be 24 bytes, because the 
inheritance is not deep enough to make sizeof 32?

Thanks,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4329 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200717/96605a7f/attachment.bin>


More information about the Development mailing list