Static/Singleton Class for Global Hash Table?

EZSundayAM
EZSundayAM used Ask the Experts™
on
I have a database table with 600 rows, that looks something like this

[ These Are Natural Key ]
Car		Part		MyDescription
char(64)	char(64)	char(256)
---		----		------------------------------------
Honda		Tire		Looks like a donut, but not as tasty
Honda		Wheel		Shiny and wears a rubber shoe
Ford		Engine		Eats gas and makes loud noise.
Chevy		Tire		Donutish but not for a Honda.

Open in new window

It's not actually car parts of course.



I need to load the entire 600 rows into memory when the user starts their app. Frequently other classes will need to return a single Description (Field3) FAST when given a Cart.Part (Field1, Field2) composite natural key. Nothing else, no sorting, lists, updating, for-each loops, just speed.

Many times in the code I'd like to do retrieve the Description (Field3) roughly like this?

string MyDescription = MyNewExpertclass.Get("Honda.Tire");


I'm a database guy mostly. It seems a Hash Table would be perfect since I know the size beforehand and don't need to update, order or loop through the data.  

Singleton doesn't seem correct, but maybe a static object containing the hash table so that it is loaded once and accessed many times throughout the application code?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Is the program multi-threaded?
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Actually, disregard my last question. If the collection will be read-only, there shouldn't be any threading issues--provided you load it fully before you start reading it.

I believe a static object would suit your purposes. Singleton ensures that only one instance of a class is in existence during the life of the application. For this purpose, I think you will achieve the same functionality using a static object.

Author

Commented:
Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial