I have been coding some octave .oct files lately (C++), and for my purposes speed is of the essence.
It seems to me that creating C++ objects (in general) can take some time. I was wondering if there is some way to circumvent this? Maybe to somehow create a statically allocated object the first time the function is called and then to return it every time. Although I don't know how it could be possible to do this memory-safely.
It is safe to assume I want to return a sparse matrix object, and I know an upper bound on the number of nonzero elements, so that all the information required for creating the object once-and-for-all exists at first function call.
Just to create the object seems to take some 0.05 seconds but the overhead of calling oct file is only on magnitude 5e-5 seconds. That is a factor of a thousand which can be very impactful if the rest of the code is heavily optimized computational C-code which often runs faster than 1e-5 seconds.