Providing more memory for mex programs in Matlab

My files compiled in Mx run out of memory (more precisely, my mxMalloc calls sometimes return NULL ). By quick calculation, I estimate that my files request mxMalloc only about 500 MB of memory (maybe up to 1 GB), and I run my files on a 64-bit Linux machine with 16 GB of memory, on which Matlab runs almost exclusively, However less, mxMalloc quite often returns NULL .

I suppose there are several reasons why this might happen (memory fragmentation, etc.), but in any case, 500 MB does not seem to be much to ask for 16 GB of memory.

I believe that my mxMalloc calls request memory from the Matlab heap, but I'm not 100% sure ( mxMalloc requests are processed by Matlab in the end, and not directly to the OS). So, is there a way to increase the heap size of my mex file?

thanks

+4
source share
1 answer

You can use malloc (not mxMalloc ), but the memory must be managed manually (for example, you must call free , it is not optional, for example mxFree ). You can also try compiling using C ++ and increasing the shared / scope pointers. Signature mexFunction you will need extern "C" .

One of the reasons you might run out of memory is because your arrays are too long. mxArray must be continuous. This way, mxMalloc them and mxFree them can fragment your memory space. Although std :: vector must be contiguous, std :: list does not have to be.

Something similar to the original STL rope class may be a good implementation.

+2
source

Source: https://habr.com/ru/post/1336533/


All Articles