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
1 2 3 4 5 6 7 |
// overload for pointers to int inline void rewire( int * A, int * B ) { int * temp = A ; A = B ; B = temp ; } |
Watch carefully.
That is the situation upon entering the rewiring function. Then:
1 |
T * temp = a ; |
And then this:
1 |
a = b |
This is where “pointer to A” loses its address. It is rewired to the same value as pointer B. Lastly:
1 |
b = temp; |
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”.