ISSHARED determines data sharing status among workspace variables

バージョン 3.0.0.0 (51.8 KB) 作成者: James Tursa
ISSHARED determines data sharing status among workspace variables
ダウンロード: 46
更新 2018/5/21

ライセンスの表示

ISSHARED determines if a variable is sharing data with other variables. This sharing takes place automatically in MATLAB behind the scenes, and normally the user need not pay attention to it. However, if the user is working with large variables, it can be a huge benefit to understand how this sharing is taking place and what actions can cause shared data copies vs deep data copies in order to write code that better manages memory and timing. The types of sharing that can be detected by this mex routine are:

Shared Data Copy --> Separate header but data pointers are shared

Reference Copy --> Variable header & data pointers are shared.
Note: Reference copies can either be direct
or through a shared "parent". See examples.
E.g., struct field elements and cell elements
are often shared this way.

Looks for sharing among ordinary workspace variables, classdef object public properties, and function handle embedded data items. This mex routine cannot always tell when empty variables are shared reference copies of each other. E.g.,
>> x = 1:3
x =
1 2 3
>> y = x
y =
1 2 3
>> isshared(x,y)
ans =
1
>> y(1) = 4
y =
4 2 3
>> isshared(x,y)
ans =
0
In the above example, the assignment y = x caused the variable y to be created such that it was sharing the same data memory as x. But when we subsequently changed one of the elements of y, suddenly the real data memory of y points to a different place. This is known as copy-on-write. MATLAB does not make a deep data copy (i.e., copying the data to a brand new memory location) until it needs to. It didn't need to for the initial y = x assignment, but it did need to when one of the elements of y was changed. ISSHARED can be used to show this type of sharing for all of the variables in the current workspace.
In addition to simply reporting if input arguments are shared, ISSHARED can generate sharing name lists for single variables, or for all of the variables in the current workspace. E.g.,
[N,M] = isshared;
N = a vector containing the number of variables in each sharing group that were detected
M = a cell array of cell array of char strings containing the names of the sharing variables

引用

James Tursa (2024). ISSHARED determines data sharing status among workspace variables (https://www.mathworks.com/matlabcentral/fileexchange/65861-isshared-determines-data-sharing-status-among-workspace-variables), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2011a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersWorkspace Variables and MAT-Files についてさらに検索
タグ タグを追加

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
3.0.0.0

Updated for R2018a

2.0.0.0

Updated for 64-bit and later versions of MATLAB. Added classdef object public property and function handle data capability.

1.0.0.0