Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Lets assume that you want to store <code>ItemList&lt;T&gt;</code> in an array.</p> <p>Allocating an array of value types (<code>struct</code>) will store the data inside the array. If on the other hand <code>ItemList&lt;T&gt;</code> was a reference type (<code>class</code>) only references to <code>ItemList&lt;T&gt;</code> objects would be stored inside the array. The actualy <code>ItemList&lt;T&gt;</code> objects would be allocated on the heap. An extra level of indirection is required to reach an <code>ItemList&lt;T&gt;</code> instance and as it simply is a an array combined with a length it is more efficient to use a value type.</p> <p><img src="https://i.stack.imgur.com/zjsEO.png" alt="Struct vs class"></p> <p>After the inspecting the code for <code>EntitySet&lt;T&gt;</code> I can see that no array is involved. However, an <code>EntitySet&lt;T&gt;</code> still contains two <code>ItemList&lt;T&gt;</code> instances. As <code>ItemList&lt;T&gt;</code> is a <code>struct</code> the storage for these instances are allocated inside the <code>EntitySet&lt;T&gt;</code> object. If a <code>class</code> was used instead the <code>EntitySet&lt;T&gt;</code> would have contained references pointing to <code>EntitySet&lt;T&gt;</code> objects allocated separately.</p> <p>The performance difference between using one or the other may not be noticable in most cases but perhaps the developer decided that he wanted to treat the array and the tightly coupled count as a single value simply because it seemed like the best thing to do.</p>
    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.
 

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