Parameters and Return Values

The prefered argunent passing method for objects is by reference. Try to avoid rerturning pointers to arrays or matrices (or generally to any component), since it is not clear, whether to delocate the returned pointer or not. The most prefered way is to create local variable of vector or matrix type, pass it (using reference) to called function. The calling function is responsible to properly resize the (output) parameter and set values accordingly. The point is, that destructors are called for local variables automatically by compiler, so there is no possibility for memory leaks and the local variable can be reused for multiple calls to target function (inside loop) and therefore there is no need for repeating memory allocation and dealocation. Sometimes it may be reasonable to return pointer to constant float array or matrix (representing for example nodal coordinates), since passing output array as parametr will require array copying.



Borek Patzak 2018-01-02