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 CenterMATLAB Answers에서 Workspace 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