Solved

COM+ / Object Pooling / DECLARE_NOT_AGGREGATABLE

Posted on 2000-03-30
3
580 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
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Build VS2015 project in bat command 3 93
Path to  STL Map header file 1 70
max float value 3 51
What namespace do I need to import? 2 38
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

828 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