Reference counting

Because objects management in the C++ programming language defaults to \ value semantics, we have to take explicit actions to avoid copying large objects -- the time spent in copying large objects may be shown to be non negligible under usual circumstances. A popular way to solve that memory management problem is to use reference counting coupled with a copy-on-write strategy.

Concretely, each object (of type VectDse, MatrDse, MatrStr, MatrSps, UPolDse or MPol, used as template-arguments for our containers) is attached with a counter whose purpose is to keep track of the number of references to its associated object. An assignment to a new object will increment the counter and copy the actual data's address. A modification of the shared object will induce a copy of the data leading to a new shared object with counter 0. The object's destructor either decrements the counter (if it is positive) or else effectively destroys the data, thereby freeing its storage.

The overall scheme is implemented by the class shared_object<R>. Therefore, returning such objects by value in a function as in

VectDse<C> F(...) { VectDse<C> W= ...; return W; }

does not induce a performance penalty. Indeed a copy and destruction of W will in this case just increment or decrement a counter.


SYNAPS DOCUMENTATION
logo