K
Kevin
Using this:
http://msdn2.microsoft.com/en-us/library/3dasc8as(VS.80).aspx
as an example I have a question concerning the reuse of objects. In
the example 10 instances of the Fibonacci class are made and then all
put in the threadpool at once, which is well within the limits of the
threadpool.
However, what happens if you want to do 10,000 Fibonacci calculations
in the threadpool? You really dont want to make 10,000 instances of
the Fibonacci class as there would be considerable memory overhead
involved.
What you want to do is create a 'bucket' of say 30 (slightly bigger
than the maxthreads of the threadpool) Fibonacci objects, and a queue
(of size 10,000) of calculations (in this case 'n'). The program
would then take a calculation off the queue populate a Fibonacci
object with the 'n' and then stick it into the threadpool.
When the object is finished, it raises an event or whatever to say it
has finished and goes back in the bucket. The main thread then sees
that there is an object in the bucket and takes another calculation
off the queue and sends the object back into the threadpool.
I am pretty sure how I would achieve this, however, I wanted to know
if there were any best practices or exising examples for this kind of
thing that people could point me to? Google searches havent returned
anything really useful.
Many thanks
Kevin
http://msdn2.microsoft.com/en-us/library/3dasc8as(VS.80).aspx
as an example I have a question concerning the reuse of objects. In
the example 10 instances of the Fibonacci class are made and then all
put in the threadpool at once, which is well within the limits of the
threadpool.
However, what happens if you want to do 10,000 Fibonacci calculations
in the threadpool? You really dont want to make 10,000 instances of
the Fibonacci class as there would be considerable memory overhead
involved.
What you want to do is create a 'bucket' of say 30 (slightly bigger
than the maxthreads of the threadpool) Fibonacci objects, and a queue
(of size 10,000) of calculations (in this case 'n'). The program
would then take a calculation off the queue populate a Fibonacci
object with the 'n' and then stick it into the threadpool.
When the object is finished, it raises an event or whatever to say it
has finished and goes back in the bucket. The main thread then sees
that there is an object in the bucket and takes another calculation
off the queue and sends the object back into the threadpool.
I am pretty sure how I would achieve this, however, I wanted to know
if there were any best practices or exising examples for this kind of
thing that people could point me to? Google searches havent returned
anything really useful.
Many thanks
Kevin