Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've got two suggestions to try: </p> <p>Firstly, what about using Reflector or ILSpy to look inside Generic <code>List&lt;T&gt;</code>? I assume that implementation isn't in the CF or you could use it. Generic <code>List&lt;T&gt;</code> is array backed and uses a doubling algorithm starting at length 4 array, every call to .Add over the Capacity causes it to double and perform an Array.Copy into the new array. It doesn't resize unless you explicitly set Capacity to zero so beware from a memory point of view. Adds are one thing but each Remove will cause the array to be copied and left-shifted after the index that was removed. </p> <p>The second suggestion is this - what about about creating a custom class which wraps an integer array to handle this which uses a similar double algorithm (or quadrupling) to Generic <code>List&lt;T&gt;</code> (to handle resizing) but starts at say size 256. You could add object integer id's to this out of order as fast as you like and it won't double too often. You could also simulate a remove by designating (int)-1 or uint.MaxValue as a "null index" meaning no Array.Copy on remove. Then, apply some sort of fast sorting per frame to sort the object index array before drawing. If you sort ascending all your -1s will appear at the start (or uint.MaxValues at end) and can be ignored. You can periodically "collect" the index array by resizing and removing the preceeding <code>-1</code>'s on a separate thread (beware - use locking ;)</p> <p>What do you think? Just thinking you will offset some computation once per frame for fast sorting (not expensive on xbox vs. memory allocation/collection on each Remove and some Adds (expensive). </p> <p><strong>UPDATE - BlockArray - List&lt;T[]&gt; where T is fixed size array</strong></p> <p>A further comment on this. I was recently experimenting with the most efficient data-structure for dynamically sized lists and discovered by experimentation that array blocks - a class which is backed by a List of T[], where each T[] was an array of fixed size block, e.g. 512, 4096, 8192 as several advantages over a plain List&lt;T&gt;. </p> <p>I found that an implementation of Add() (where size is unknown) in a List&lt;T[]&gt; vastly outperformed Add() for List&lt;T&gt;, especially when the total size became larger. This is due to List&lt;T&gt;'s doubling algorithm which requests a new array 2x the size of the old, and memcpy's the old array over whenever size is exceeded. </p> <p>Iterating speed is similar. Pre-allocation (pre-defined capacity) was much slower than List&lt;T&gt; for small block sizes (512), but only slightly slower for large block sizes (8192). Removes are problematic, as require copying/left shifting many blocks.</p> <p>What's interesting is in a List&lt;T[]&gt; (block list), you can cache/pool the blocks. If small enough, blocks of T[] fit into the small object heap (favouring compaction, quicker allocation), may fit into the L2 cache and a number of blocks could be pre-allocated and pooled</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. 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