ConicBundle
|
A typical problem in using overloaded arithmetic operators for C++ matrix classes is the frequent generation of temporary automatic matrix variables by the compiler. This does not only need a lot of copying but also leads to a lot of interaction with the memory manager. In particular, in the typical situation of the use of many matrices with very slight changes in size, severe memory fragmentation problems may occur with the standard memory manager.
In order to reduce this effect, the library usees a very naiv but sufficiently efficient memory manager of its own (see Classes and Functions for Memory Management) for the internal value arrays of the matrix classes. In particular, it allocates only blocks of size 2^n for appropriate sizes of n, and retunrs such a block for any request that fits in [2^(n-1),2^n]. It never frees any memory, except when the memory manager is destructed, but keeps the blocks that are returned by destructed matrices, in order to serve the next request for the same amount. The memory manager is initialized as soon as one class derived from CH_Matrix_Classes::Memarrayuser is instantiated and it is destructed, whenever the number of instantiated Memarrayusers drops to zero.
In consequence, operations like appending a scalar to a vector are very efficient and cause additional copying only if the size exceeds a 2^n threshold, i.e., the work involved in appending a scalar is O(1) in amortized sense.