Will MATLAB 'move' or '' copy the return value?

Given the following code

function [out] = doit() out = [1,2,3,4,5,6]; end tmp = doit(); 

Will MATLAB copy the out memory to tmp or transfer it directly to tmp ?

+5
source share
1 answer

In MATLAB there is nothing like a pointer, there are local workspaces .

MATLAB seems to be smart, and makes a copy and returns when necessary, and passes a "pointer" (without your knowledge) if it is not required. As noted @Daniel and @zeeMonkeez, discussed in Loren blog here , and it clearly responds to the reset function, when the memory was created inside here . The general idea in these posts is that β€œMATLAB will not copy unless needed”

Basically, MATLAB abstracts you from memory management.


Sidenote: There is something like pointers if you really need to use this. See Comment by @excaza.

+7
source

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


All Articles