Dejan Jovanović wrote:
I'm writing an application with intense usage of integers and one of the operations that might have a performance impact is swapping two numbers. I don't know the internals of the CLN library and I see there is no swap operation in the headers.
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) }
My worst-case guess is: (1) a sequence of constructors (2) reconstruction of a (3) destruction of a, reconstruction of b (4) destruction of b, reconstruction of temp (5) destruction of temp
No, thanks to reference counting, your implementation of swap(a,b) is of O(1) in the integer length of both operands. The manual has mention of the reference counting in some places.
Also, would massive amount of swaps lead to internal memory fragmentation due to construction/destruction?
No, no reason to worry. -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>