I have large objects that I want to access via a string identifier. My current approach is to use a Dictionary containing those:
var myObjects = new Dictionary<string, LargeObjectClass>(); var specificObject = myObjects["identifier"]; Now I was wondering whether storing many of those large objects in the Dictionary might be bad for performance and I would be better off using a Dictionary to store indices into an array that actually stores the objects:
var myObjects = new LargeObjectClass[size]; var objectIndices = new Dictionary<string, int>(); var specificObject = myObjects[objectIndices["identifier"]]; This is obviously a bad approach if the size of myObjects is unknown in advance or might change at runtime, but since the Dictionary is smaller and I read somewhere that arrays are more efficient than Dictionaries, I thought this approach might have a better performance in cases where the size is fixed.
Which of these approaches is more efficient, assuming the objects are very large?