Azzera filtri
Azzera filtri

what is the extra data in a dictionary?

8 visualizzazioni (ultimi 30 giorni)
min lee
min lee il 9 Apr 2024
Commentato: Stephen23 il 9 Apr 2024
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 Commenti
Manikanta Aditya
Manikanta Aditya il 9 Apr 2024
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 il 9 Apr 2024
"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."

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Dictionaries in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by