Matlab: avoiding memory allocation in mex

I am trying to make my mex library to avoid memory allocation, which is even so. So far, mex got input, created some matrices with help mxCreate...()and returned this output.
But now I would like to change this interface so that mex itself does not make any allocations.
What I had in mind is that mexFunction will receive an input matrix to fill in the values โ€‹โ€‹and return the same matrix as output.

Is it possible?

The little anxiety that made me think that this is generally something I need to do is that the left hand arguments come to mexFunction as const, and the right hand argument is not constant. in order to return the input matrix as output, I need to remove this constant.

+3
source share
2 answers

Oddly enough, I just looked at it the other day. The best information I have found is topics here and here , as well as this .

Basically this is considered very bad in the Matlab world ... but at the same time, nothing stops you, so you can do it - try simple examples and you will see that the changes are propagating. Just make changes to the data you receive from prhs (you do not need to return anything - since you changed the raw data, they will be reflected in a variable in the work area).

, , - Matlabs copy-on-write. format debug . a=b, , a b " " , , , pr . , y Matlab, copy-on-write , , y . mex, , , y, x .

, , , , - - , , , . , .

+5

. , , , , .

, , , , API MEX.

+5

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


All Articles