September 11, 20241 yr In previous posts, we've explored relocation, trivial relocation, and their use in optimizing data structures like vector-like containers. We've also examined how trivial relocation relates to move assignments, enabling further optimization of operations like swaps and algorithms such as std::sort and std::rotate. Qt and Trivial Relocation (Part 5) by Giuseppe D'Angelo From the article: Is trivial relocation allowed in Standard C++? ThatÎÃÃs probably a question we should have asked as soon as we started this journey. Of course, the answer isâ¬Ã¡no, it is not allowed! Remember how trivial relocation works: we useâ¬Ã¡memcpyâ¬Ã¡a source object(ÎÃÿs representation) into some storage, and claim that operation realizes the equivalent of move-constructing the source into that storage, plus destroying the source. The problem is that one canÎÃÃt just put data into some storage and pretend that an object exists in there. This is only allowed for a specific set of types, such asâ¬Ã¡trivially copyableâ¬Ã¡types. (Note that if a type is trivially copyable, thenâ¬Ã¡Qt automatically considers it trivially relocatable.) However, as we have discussed, many interesting types (QString,â¬Ã¡std::vector,â¬Ã¡std::unique_ptr, Îê) are not trivially copyable, but they would still benefit from trivial relocatability. View the full article
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.