I have a function that takes in a couple of large multi-dimension float arrays as input. As a result, I crash the stack.
I'm a beginner to C/C++ so I will apologize in advance if this question is dumb. Anyways, after looking around the net, this problem is not particularly new and the general solution is either make it as a global variable or use vector (instead of array).
However, this piece of C++ code was intended to be used as a shared library and takes input from a Python script and returns (or modifies) the value (also in arrays). Therefore I don't think it would be possible to declare as global (correct me if I am wrong).
So, apart from using vector, is there any other way to do so? The reason that put me off from using C++ vector is there is no equivalent data type in Python. I'm using ctypes for communication between Python and C++ if that matters.
There is no way in C/C++ to pass an array as a function argument by value. You can pass a pointer to the array and the size of the array. In C++, you also can pass a reference to the array and the size of the array (in template parameters). In either case, the array is not copied and the called function accesses the array in-place, where the caller allocated it.
Note that the array can be wrapped in a structure, in which case it can be passed by value. In C++, std::array is an example of such. But the caller has to initialize that structure instead of the raw array. std::vector is similar in that it is a structure and it automatically copies elements when the vector is copied, but unlike C arrays and std::array it dynamically allocates memory for the elements.
However, if you're integrating with C API, you are most likely limited to a pointer+size or pointer+size wrapped in a C structure solutions. The rules of working with the array (e.g. who allocates and frees the array, are writes to the array allowed, etc.) are specific to the particular API you're working with. Often, there is a dedicated set of functions for working with arrays provided by the library. You should read the API documentation about conventions taken in Python.
C++ - How to take a large array as input for a function