Solved

COM+ / Object Pooling / DECLARE_NOT_AGGREGATABLE

Posted on 2000-03-30
3
570 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
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
gelbert earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now