Several functions in a C++ OpenCV project I am working on use local Mat (and UMat) variables as temporary buffers for internal computations.
I would like to prevent these functions to allocate memory for all their local Mat variables every time they are called. The purpose of this is not to use less memory, but to make sure memory is available or fail at the first call and to prevent any possible overhead due to memory allocation.
To prevent reallocations, I thought about declaring the local Mat variables as static and making sure they will always store the same data size and type within the functions, despite I do not care about carrying the data they store across multiple calls.
Does this approach make sense? Am I doing it the wrong way, or is there a better/safer one?