I have the source.cpp code. Here is his fragment:
extern "C" bool some_function(int x){ CustomClass my_object = SlowCustomClassCreator(); return my_object->get_result(x); } I compiled it into the SomeLib.so library. I added the library to the project on Unity and in one of the .cs scripts I call the function some_function from this library.
The problem is that each call creates a my_object object and creates it for a long time (despite the fact that the execution of the get_result function get_result fast). How can I make my_object somehow stored in memory between function calls and not need to be re-created?
Added: code on the C # side
[DllImport("SomeLib")] private static extern int some_function(int x);