views:

74

answers:

2

In my server application (written in C#), I need to create a pool of same type of objects. I pull an object from pool when I need, and it goes back to pool when it is no longer needed. Mechanism needs to be thread safe since different threads will be asking and submitting these objects. I understand that frequently locking something to make thread-safe has an adverse effect on application performance. Can you suggest a design by which I can even avoid explicit locks?

Please can you suggest the way I can accomplish above? Ability to resize the pool (create additional if running short of objects) would be a great add-on.

Thanks in advance...

+2  A: 

This post will be of interest:

http://stackoverflow.com/questions/1698738/objectpoolt-or-similar-for-net-already-in-a-library

spender
+1 Looks interesting! Let me check it out...
Hemant
+1  A: 

I've had good luck with this one on CodeProject. I only had to make a minor tweak to how WeakReferences are stored, but other than that, it's running in production with no problems at all.

Kilhoffer