Monday, February 1, 2010

What is an object pool in .NET?

An object pool is a container of objects that holds a list of other objects that are ready to be used.
It keeps track of:
  • Objects that are currently in use
  • The number of objects the pool holds
  • Whether this number should be increased
The request for the creation of an object is served by allocating an object from the pool.
This reduces the overhead of creating and re-creating objects each time an object creation is required

Why is an Object Pool required?

The request for the creation of an object is served by allocating an object from the pool.
This reduces the overhead of creating and re-creating objects each time an object creation is required.

How does object pooling and connection pooling differ?

In Object pooling, you can control the number of connections.
In connection pooling, you can control the maximum number reached.
When using connection pooling, if there is nothing in the pool, a connection is created since the creation is on the same thread.
In object pooling, the pool decides the creation of an object depending on whether the maximum is reached which in case if it is, the next available object is returned. However, this could increase the time complexity if the object is heavy.

0 Comments: