What C# "List" is most optimized for repeated lookups?

Viewed 73

When I say list, I mean List, array, HashTable, things like that where you can iterate through with an IndexOf method.

I have a program that wants to make many repeated lookups to its lists, which is obviously slow if you have a list format that iterates through every value starting at 0 every time you do an IndexOf (and to a lesser extent slower than a direct reference when using hashtables with many many lookups). Before I do this, I want to ask;

  1. Is there an existing IEnumerable that is optimized for repeated lookups?
  2. Assuming this hypothetical IEnumerable keeps a reference of the lookup, (giving a key to the object doing the lookup to be stored), is this even a good idea in terms of locking in items that the garbage collector could pick up? Is there a way to mark fields as not "not important to keep in memory despite a reference existing" and "garbage-collectible"? (This isn't a problem I don't know how to fix as much as it would be something I would rather implement rather than working around)

If the answer to either of these is "no", then I'll make an IList that keeps a reference of the last index of a lookup, which wouldn't bog up the garbage collector.

The program I'm working on is a UI system, where Widgets tend to take up a decent amount of memory as well as changing a lot, leaving a garbage collector as my only means freeing up memory. Willy nilly references laying around are dangerous to account for.

0 Answers
Related