I have a program which has to do a lot of lookup.
there are multiple threads running in parallel and all of these threads have to do a lookup on the same list of words.

Currently i'm storing the list of words in a dictionary in each of the threads.

Is there some way i can use a static class which contains the list of all the words so that all the threads can just call a method of this static class and the class returns the result based on lookup.

I want to to this cos i don't want multiple copies of the same data on my memory.

Any suggestions...

Recommended Answers

All 2 Replies

I would also like to know the following.

If i have a static class in my application, does the class get instantiated as soon as the application is started. If so , can i write a static constructor which will load the lookup lists/dictionaries ?

Yes you can, just declare the class as static and all the methods/properties as static.

A static class is instantiated when the system decides it wants to do it but always before your first use of the class. You don't have to worry about when that happens, it just works (like magic :)).

And yes, you can have a static constructor. You can read about them here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.