필터 지우기
필터 지우기

what is the extra data in a dictionary?

조회 수: 8 (최근 30일)
min lee
min lee 2024년 4월 9일
댓글: Stephen23 2024년 4월 9일
When a matrix is converted to a dictionary, the memory assumption increases as demonstrated below. What is the extra data in a dictionary?
>> b = [1:10; 1:10];
>> whos b
Name Size Bytes Class Attributes
b 2x10 160 double
>> a = dictionary(b(1,:), b(2,:));
>> whos a
Name Size Bytes Class Attributes
a 1x1 304 dictionary
  댓글 수: 3
Manikanta Aditya
Manikanta Aditya 2024년 4월 9일
The extra data in a dictionary compared to a matrix in your example is likely due to the overhead of the dictionary data structure.
A dictionary, unlike a matrix, needs to store additional information such as keys and possibly some metadata for each key-value pair. This extra information results in an increase in memory usage.
In your example, the dictionary a uses 144 bytes more than the matrix b. This additional memory is consistent across different sizes of the matrix and dictionary, suggesting that it’s a fixed overhead cost for using the dictionary data structure.
Stephen23
Stephen23 2024년 4월 9일
"A dictionary, unlike a matrix, needs to store additional information"
All arrays (even numeric ones) store a header with array meta-information, such as the type, dimensions, and attributes. This is explained in the MATLAB documentation: "MATLAB arrays (implemented internally as mxArrays) require room to store meta information about the data in memory, such as type, dimensions, and attributes. This takes about 104 bytes per array. This overhead only becomes an issue when you have a large number (e.g., hundreds or thousands) of small mxArrays (e.g., scalars). The whos command lists the memory used by variables, but does not include this overhead."

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Dictionaries에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by