フィルターのクリア

Memory management - variable size array

3 ビュー (過去 30 日間)
Adrián László Szemenyei
Adrián László Szemenyei 2024 年 2 月 25 日
コメント済み: Walter Roberson 2024 年 2 月 25 日
I'm reading Yair Altman's Accelerating MATLAB® Performance book (2015 edition) and and on pg. 429 it states " Variable-sized arrays are required if we use functionality such as the find function or logical indexing." and "Variable-sized arrays that have an upper size limit are either statically or dynami cally allocated, depending on the coniguration for dynamic allocation. (...) Variable-sized arrays with unbounded maximal size are the least eficient. They are always allocated on the heap at run time, using dedicated internal functions. The allocation and reallocation costs in this case are maximal."
My questions are:
  1. Is variable sized array what i think it is i.e. a variable (e.g. and array) which does change size during the execution of the program like
A=[];
For i=1:100
A(end+1)=i;
end
or somehow one has to explicitly write that my X variable should be considered fixed-sized.
2. If it is the former then why an array has to be fixed-size for the find function or indexing?
(I think I understand what is heap and stack memory, and when to use which in languages where you can explicitly do that like C and C++)
(Also if one has good detailed articles or blog posts considering matlab's memory management, I would be glad if you could share them.)

採用された回答

Walter Roberson
Walter Roberson 2024 年 2 月 25 日
At the MATLAB level, nearly everything is a variable-sized array. There are relatively few objects that enforce fixed-array limits behaviour, and those objects are mostly treated as variable-size internally. (There is the possible exception for "system objects" -- they are possibly treated internally as fixed size.)
The concern about variable-sized array compared to fixed-size array is relevant for Simulink and Embedded Coder and MATLAB Coder.
  2 件のコメント
Adrián László Szemenyei
Adrián László Szemenyei 2024 年 2 月 25 日
and variable-sized arrays are stored in the heap, thus MATLAB seldomly uses the stack?
Walter Roberson
Walter Roberson 2024 年 2 月 25 日
MATLAB variables are not normally stored in the stack, but variables in MATLAB Function Blocks (for Simulink) are generally stored in the stack.
MATLAB keeps a pool of "small blocks"; I no longer recall whether those blocks are 512 bytes or 1024 bytes. These blocks are in a reserved area of memory; it would be incorrect to call it a heap.
MATLAB keeps a heap of larger blocks.
We figure that MATLAB also allocates individual virtual memory zones for "sufficiently large" blocks, so that deallocating the variable has the effect of returning the memory to the operating system (which is something that does not happen to variables on the heap.)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCode Generation についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by