Hi Dejan,
I see there is no swap operation in the headers.
There is no swap operations in the headers because the code with assignments that you wrote is fast enough.
would massive amount of swaps lead to internal memory fragmentation due to construction/destruction?
No. Every heap-allocated object of CLN has a reference count. Therefore, swapping the contents of two variables really only swaps pointers and is O(1), regardless of the magnitude or precision of the numbers.
Could someone please elaborate how much stuff happens internally when I do the usual swap:
void swap(cl_I& a, cl_I& b) { (1) cl_I temp; (2) temp = a; (3) a = b; (4) b = temp; (5) }
(1) temp gets assigned a default value (0 IIRC). (2) The reference count of the object pointed to by a gets incremented. (3) The reference count of the object pointed to by b gets incremented, and the reference count of the object originally pointed to by a gets decremented. (4) The reference count of the object originally pointed to by a gets incremented, and the reference count of the object originally pointed to by b gets decremented. (5) The reference count of the object originally pointed to by a gets decremented. For fixnums, which have no memory allocation, of course no reference count exists. If even this O(1) is code turns out to be a bottleneck, there is also the possibility of using the placement-new operator. But since it is easy to produce memory leaks with this technique, I don't recommend it unless you *really* have a bottleneck here. Bruno