Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For strings, you could perhaps look at interning; either with the inbuilt interner, or (preferably) a custom interner - basically a <code>Dictionary&lt;string,string&gt;</code>. What this means is that <strong>each identical string uses the same reference</strong> - and the duplicates can be collected.</p> <p>Don't do anything with the int; that is already optimal.</p> <p>For example:</p> <pre><code>using System; using System.Collections.Generic; class StringInterner { private readonly Dictionary&lt;string, string&gt; lookup = new Dictionary&lt;string, string&gt;(); public string this[string value] { get { if(value == null) return null; if(value == "") return string.Empty; string result; lock (lookup) { // remove if not needed to be thread-safe if (!lookup.TryGetValue(value, out result)) { lookup.Add(value, value); result = value; } } return result; } } public void Clear() { lock (lookup) { lookup.Clear(); } } } static class Program { static void Main() { // this line is to defeat the inbuilt compiler interner char[] test = { 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd' }; string a = new string(test), b = new string(test); Console.WriteLine(ReferenceEquals(a, b)); // false StringInterner cache = new StringInterner(); string c = cache[a], d = cache[b]; Console.WriteLine(ReferenceEquals(c, d)); // true } } </code></pre> <p>You could take this further with <code>WeakReference</code> if desired.</p> <p>Note importantly that you <strong>don't need to change your design</strong> - you just change the code that populates the object to use the interner/cache.</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