Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Reference types do not create duplicate objects as you pass them around. Under the covers, basically you are passing around pointers. So if you have N objects, you will have N x memory per object + the memory required to reference each object. This is regardless of the storage container for those references, in your case, a dictionary. You'll incur some memory cost for the dictionary, but if you created another dictionary and put all the same objects in it, you would only have 2x Dictionary memory costs plus one set of objects in memory. This is when you are using reference types.</p> <pre><code>MyObject object = new MyObject(); // one object created in memory MyObject object2 = object; // still only one object created in memory, but we have two references now </code></pre> <p>Value types are always unique in memory. So if you create a dictionary of System.Int32 and then create a duplicate of the dictionary, you will have a copy of each value in the dictionary as well.</p> <pre><code>int myInt = 5; // one int created in memory int myInt2 = myInt; // two ints have been created in memory </code></pre> <p>So let's figure out what memory chunks are allocated for certain scenarios: </p> <pre><code>// two value types Dictionary&lt;int, int&gt; myDictionary1 = 1 x Dictionary N x int &lt;key&gt; N x int &lt;value&gt; Dictionary&lt;int, int&gt; myDictionary1 + Dictionary&lt;int,int&gt; myDictionary2 (clone of 1) = 2 x Dictionary 2N x int &lt;key&gt; 2N x int &lt;value&gt; // reference types Dictionary &lt;string, MyObject&gt; myDictionary3 = 1 x Dictionary N x string Reference N x string instance (if they are all unique) N x Object Reference N x Object instance (if they are all unique) Dictionary &lt;string, MyObject&gt; myDictionary3 + Dictionary &lt;string, MyObject&gt; MyDictionary4 (clone of 3) = 2 x Dictionary 2N x string reference 1N x string instance (if they are all unique) 2N x Object reference 1N x Object instance (if they are all unqiue) </code></pre> <p>You're scenario:</p> <pre><code>Dictionary&lt;int, MyObject&gt; myDictionary5 1 X Dictionary N X key N X value reference N X value object Dictionary&lt;int, MyObject&gt; myDictionary5 + Dictionary&lt;int, MyObject&gt; myDictionary6 (clone of 5) = 2 x Dictionary 2N x key 2N x value reference 1N x value objects </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload