Solved

COM+ / Object Pooling / DECLARE_NOT_AGGREGATABLE

Posted on 2000-03-30
3
585 Views
Last Modified: 2013-11-25
With a VB component object pooling is not possible.  With a C++ component it is but can lead to very strange results and data corruption.  From the brief MS help: When pooling is enabled objects will be recycled and reused.  Object pooling can only be enabled for components that a written to meet the reusability requirements for poolable objects.  

Sounds good!  Questions:

1) Can someone explain from an implementation point of view in C++ what would be needed to support object pooling?

2) Why would you ever choose not to enable pooling?

3) Any comments on JIT activation?

Thanks!
0
Comment
Question by:eeuserex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
gelbert earned 100 total points
ID: 2670934
Requirements for Poolable Objects
[This is preliminary documentation and subject to change. This technology works only on computers running Windows 2000 Beta 3 or later.]

Poolable objects must meet certain requirements to enable a single object instance to be used by multiple clients.

Stateless
Poolable objects should hold no client-specific state from client to client, to maintain security, consistency, and isolation. You can manage any per-client state using IObjectControl, performing context-specific initialization with Activate and cleaning up any client state with Deactivate. For more detail, see Controlling Object Lifetime and State.

No thread affinity
Poolable objects cannot be bound to a particular thread, otherwise performance could potentially be disastrous. For this reason, poolable objects cannot be marked Apartment model, they must run in the Multi-Threaded Apartment or the Neutral Apartment. In addition, poolable objects should not use thread local storage (TLS), nor should they aggregate the Free-Threaded Marshaller (FTM). For more detail about threading in COM+, see Concurrency.

Note that currently, the Microsoft Visual Basic development environment can only create Apartment model components. For this reason, Visual Basic components cannot be pooled.

Aggregatable
Poolable objects must support aggregation– that is, they must support being created with a pUnkOuter. When COM+ activates a pooled object it will create an aggregate to manage the lifetime of the pooled object and to call methods on IObjectControl. For details on writing aggregatable objects, see Aggregation.

Transactional components
Poolable objects that participate in transactions must manually enlist managed resources. If your object holds a managed resource such as a database connection while it is pooled, there will be no way for the resource manager to automatically enlist in a transaction when the object is activated in given context. Therefore, the object itself must handle the logic of detecting the transaction, turning off the resource manager's auto-enlistment, and manually enlisting any resources that it holds. In addition, a transactional pooled object should reflect the current state of its resources in IObjectControl::CanBePooled. For more detail, see Pooling Transactional Objects.

Implement IObjectControl to manage the object lifetime
Poolable objects should implement IObjectControl, though it is not strictly necessary to do so. Transactional components that are pooled, however, must implement IObjectControl. They should monitor the state of the resources they hold and indicate when they can't be reused; when CanBePooled returns false it will doom a transaction. For more detail, see Controlling Object Lifetime and State.

Language restrictions
Currently, components developed using Microsoft Visual Basic cannot be pooled, as these components will be apartment-model threaded.

Legacy components
Components can be pooled even if they are not specifically written with this in mind, so long as they are non-transactional and conform to the appropriate requirements above. It is not necessary to implement IObjectControl; a component that does not do so simply won't participate in managing its lifetime. If CanBePooled is not implemented, the object will always be reused, up until the pool maximum size.

0
 

Author Comment

by:eeuserex
ID: 2671107
Thanks for the information.  If you can answer the specific questions I would be happy to accept your comment as an answer.  Also, where did you find that specific documentation?
0
 

Author Comment

by:eeuserex
ID: 2671124
Found it on MSDN.  Also some other goodies...

Thanks.  For anyone else:

http://msdn.microsoft.com/isapi/msdnlib2.idc?theURL=/library/psdk/cossdk/pgservices_objectpooling_6ep3.htm
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question