Does evalin make a copy or use a reference to the base variable?

1 回表示 (過去 30 日間)
user86753
user86753 2019 年 11 月 12 日
回答済み: Walter Roberson 2019 年 11 月 12 日
Does evalin use additional memory when assigning the variable in the function or does it use a reference?
alpha = evalin('base','alpha');

採用された回答

Walter Roberson
Walter Roberson 2019 年 11 月 12 日
At one level of abstraction, calling a function normally is equivalent to pulling out the function header and setting up the parameter list, and then using eval on the code.
eval() and evalin() are not somehow emulating code: they use the normal internal expression tokenizer, getting back a parse tree, which is submitted to the execution engine. This is not just "like" how matlab executes functions and scripts: it is how matlab executes functions and scripts.
Thus, evalin() processes the same way the line of code would be processed intthat environment (except possibly details of caching), so it would give whatever result that code would. Which is to say that copy-on-write is used, which provides references to variables.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品


リリース

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by