I'm about to write a Mex File, so I can use my c++ code in MATLAB.
This code is built around a singleton class (in c++).
I've read that for memory to be persistent I have to use MxAlloc isntead of malloc/new, is this true for all memory I use? I.e, the class I have uses vectors, and vectors automatically allocate new memory, using standard mechanisms.
So will a vector in a class allocated using MxAlloc have trouble keeping it's memory?
You only use MxAlloc for the data that you are going to return to Matlab. Everything that stays within your library can be allocated normally.
One issue you may want to be aware of is that your library can be unloaded at any time. Normally when the user calls your mexFunction the library is loaded and will stay loaded for subsequent calls. However, at anytime Matlab may unload your library and so all the resources in your mexFunction will be freed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With