In the previous posts of this series (if you’ve missed them: parts 1, 2, 3, and 4), we have learned about relocation and trivial relocation. We have explored what relocation means, what trivial relocation means, and how it can be used to optimize the implementation of certain data structures, such as the reallocation of a […]
Author Archives: Giuseppe D'Angelo
Qt and Trivial Relocation (Part 4) On trivial relocation and move assignments
In the last post of this series we learned that: erasing elements from the middle of a vector can be implemented, in general, via a series of move assignments, move constructions, swaps, destructions for types with value semantics, the exact strategy does not really matter for types with write-through reference semantics, the strategy matters, because […]
Qt and Trivial Relocation (Part 3) Trivial relocability for vector erasure, and types with write-through reference semantics
In the last post of this series we started exploring how to erase an element from the middle of a vector. We discussed that in principle there are several different possible ways to implement erase().For instance, a vector could move-assign over the elements to be erased: Alternatively, a vector could use rotations or some other […]
Qt and Trivial Relocation (Part 2) Relocation and Erasure
In the last post of this series we discussed the usage of trivial relocation in order to optimize move construction followed by the destruction of the source. To quickly recap: objects of certain datatypes (“trivially relocatable” types) can be moved in memory by simply moving bytes; this can be used to optimize certain bulk operations […]
Qt and Trivial Relocation (Part 1) What is relocation?
The container classes introduced in Qt 4 (Tulip, for the aficionados) had an interesting optimization: the ability to turn certain operations on the contained objects into byte-level manipulations. Example: vector reallocation Consider the reallocation of a QVector<T>: when the vector is full and we want to insert a new value (of type T), the vector […]
PSA: QPointer has a terrible name
Today’s blog post is about a small utility class in Qt with a… questionable name: QPointer. If you’re new to Qt, maybe don’t check out QPointer’s documentation just yet, and try to guess what the class does based on its name alone. I’ve seen countless users being very confused by it. Some end up using […]
See you in Berlin in November 2023?
In just a couple of months, there’s going to be not one, not two, not three, but four fantastic developer events in Berlin! We are not going to miss any of them, and so shouldn’t you. November 12-14: Meeting C++ If you are a C++ developer, do not miss the 2023 edition of Meeting C++. […]
Pimpl for Small Classes
The familiar solution for thick value classes that want to preserve binary compatibility is to use the pimpl pattern (private implementation), also known as d-pointer (pointer to data). In future versions of our class, we can freely change the contents of the pimpl (i.e. adding, removing, and/or modifying data members) but the binary compatibility of […]
FMA Woes
Floating-point math is hard, and compilers will exploit every language loophole to make our FP calculations go faster, sometimes with surprising results.
QObjects, Ownership, propagate_const and C++ Evolution Const Correctness in Qt Applications
A very common implementation pattern for QObject subclasses is to declare its child QObjects as data members of type “pointer to child.” Raise your hand No, keep your hand on your computer input device 🙂 Nod if you have ever seen code like this (and maybe even written code like this yourself): A fairly common […]