Big Hashtable or big Assembly Resource File?

  • Thread starter Thread starter Dennis Myrén
  • Start date Start date
D

Dennis Myrén

Hi.

I would need an advice here please.

I have to define a set of constant key/value pairs for my C# .NET DLL
component.
We are talking about at least 5000 pairs
(where each key is a System.String and the corresponding value preferably is
a System.Byte [0x4] )

These pairs will only have to load at special occasions.

What would you think is the best approach, using a big static
System.Collections.Hashtable
loaded as needed, or using an Assembly Resource File loaded as needed?
Or perhaps there is another way? I can't think of any.

I am seeking the best way in a performance/efficiency point of view.

Thank you, Dennis
 
Dennis Myrén said:
I have to define a set of constant key/value pairs for my C# .NET DLL
component.
We are talking about at least 5000 pairs
(where each key is a System.String and the corresponding value
preferably is a System.Byte [0x4] )

These pairs will only have to load at special occasions.

What would you think is the best approach, using a big static
System.Collections.Hashtable
loaded as needed, or using an Assembly Resource File loaded as needed?
Or perhaps there is another way? I can't think of any.

I am seeking the best way in a performance/efficiency point of view.

A hashtable is definitely the fastest. It doesn't matter in memory
usage that much, as with both you have to construct the complete datastore
for a single entry. The hashtable takes some time to setup, especially
with a lot of entries (so set the initial size correctly!), where a
resource file is loaded immediately (or is even compiled into the
assembly). However once the hashtable is setup, stringsearches are very
fast, much faster than the linear search in a resource.

FB
 
Thank you!


Frans Bouma said:
Dennis Myrén said:
I have to define a set of constant key/value pairs for my C# .NET DLL
component.
We are talking about at least 5000 pairs
(where each key is a System.String and the corresponding value
preferably is a System.Byte [0x4] )

These pairs will only have to load at special occasions.

What would you think is the best approach, using a big static
System.Collections.Hashtable
loaded as needed, or using an Assembly Resource File loaded as needed?
Or perhaps there is another way? I can't think of any.

I am seeking the best way in a performance/efficiency point of view.

A hashtable is definitely the fastest. It doesn't matter in memory
usage that much, as with both you have to construct the complete datastore
for a single entry. The hashtable takes some time to setup, especially
with a lot of entries (so set the initial size correctly!), where a
resource file is loaded immediately (or is even compiled into the
assembly). However once the hashtable is setup, stringsearches are very
fast, much faster than the linear search in a resource.

FB
 
Back
Top