c# - Why does sortedDictionary need so much overhead? -


long b = gc.gettotalmemory(true); sorteddictionary<int, int> sd = new sorteddictionary<int, int>(); (int = 0; < 10000; i++) {     sd.add(i, i+1); } long = gc.gettotalmemory(true); console.writeline((a - b));             int reference = sd[10];     

output (32 bit):

280108 

output (64 bit):

480248 

storing ints alone (in array) require 80000.

internally sorteddictionary<tkey, tvalue> uses treeset<keyvaluepair<tkey, tvalue>>. tree uses node<t> , uses references between nodes, in addition each key , value have references left , right nodes additional properties. node<t> class each instance has traditional overhead of reference type. furthermore, each node stores boolean called isred.

according windbg/sos size of single node on 64 bits in 48 bytes 10000 of them take @ least 480000 bytes.

0:000> !do 0000000002a51d90  name:            system.collections.generic.sortedset`1+node[[system.collections.generic.keyvaluepair`2[[system.int32, mscorlib],[system.int32, mscorlib]], mscorlib]] methodtable: 000007ff000282c8 eeclass:     000007ff00133b18 size:        48(0x30) bytes     <== size of single node file:            c:\windows\microsoft.net\assembly\gac_msil\system\v4.0_4.0.0.0__b77a5c561934e089\system.dll fields:               mt    field   offset                 type vt     attr            value     name 000007feeddfd6e8  4000624       18       system.boolean  1 instance                0     isred 000007feee7fd3b8  4000625       20 ...int32, mscorlib]]  1 instance 0000000002a51db0 item 000007ff000282c8  4000626        8 ...lib]], mscorlib]]  0 instance 0000000002a39d90 left 000007ff000282c8  4000627       10 ...lib]], mscorlib]]  0 instance 0000000002a69d90 right 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -