C++ the good parts — std::swap


What is Pointer Rewiring aka Relinking?


Since a “pointer” is a much-feared word, let’s clarify what is pointer rewiring/relinking. That is the idiom used to speed up nontrivial types of moving. You do not move them, you swap their internals.

Let’s visualize this function

Watch carefully.

Pointer rewiring START

That is the situation upon entering the rewiring function. Then:

Pointer rewiring step ONE

And then this:

Pointer rewiring step TWO

This is where “pointer to A” loses its address. It is rewired to the same value as pointer B. Lastly:

Pointer rewiring step THREE

Now B is rewired to the “value A”. Effectively pointers A and B have exchanged addresses of the values they have been pointing to. The pointers themselves have changed. They have been  “rewired”.

%d bloggers like this: