Home
Fractals
Tutorials
Books
My blog
My LinkedIn Profile

BOOKS i'm reading

Napoleon Hill Keys to Success: The 17 Principles of Personal Achievement, Napoleon Hill, ISBN: 978-0452272811
The 4-Hour Workweek: Escape 9-5, Live Anywhere, and Join the New Rich (Expanded and Updated), Timothy Ferriss, ISBN: 978-0307465351
The Fountainhead, Ayn Rand, ISBN: 0452273331
Web Hosting Canada

mailto:olivier@olivierlanglois.net

Archives for: June 2007, 28

06/28/07

Permalink 10:12:23 pm, by lano1106, 358 words, 10771 views   English (CA)
Categories: C++

Aggregating a Free Threaded Marshaller to a COM object

That is a question a co-worker of mine asked. I did remember that I used to know what it does mean, but earlier today when I came back home, I have double checked in my COM reference book and I have found a subsection dedicated to the subject.

COM deals with multithreading by defining an apartment concept. 2 Apartment types exist: The single threaded apartment (STA) and the Multi-threaded apartment (MTA). One of the numerous COM class attributes is in which apartment type objects of that class are allowed to run. 3 values are possible for that attribute: STA, MTA or both.

When a thread wants to access a STA object, it will go through the same process than if the object was remote and will go through a proxy object, marshalling/unmarshalling and the thread residing in the remote STA apartment which must have a message loop, will receive the request. This whole process adds a lot of overhead and for that reason, COM allows to create a custom marshaller. Your COM object would have to implement the interface IMarshal. One example of a custom marshaller would be to serialize the whole object state to create an exact copy of it on the proxy side so once unmarshalled, all access to it would remain local.

Now, (I know the short explanation is starting to be long), in the case that a developer went through the process of making his COM class thread safe to support MTA, it would be a good idea to have a custom marshaller to just serialize a raw pointer to it for a safe direct access even when it reside in a STA apartment. This situation is so common that COM provides the custom marshaller that does it. It is the famous Free Threaded Marshaller and since COM does not allow inheritance to reuse code, the only way is to aggregate it to your COM object with the function CoCreateFreeThreadedMarshaler().

Aggregating a COM object just mean that when QueryInterface is called for getting an interface that the outer COM object does not support, it will forward it to the IUnknown::QueryInterface of the aggregated object.

Olivier Langlois's blog

I want you to find in this blog informations about C++ programming that I had a hard time to find in the first place on the web.

June 2007
Sun Mon Tue Wed Thu Fri Sat
 << < Current> >>
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Search

Custom Search

Misc

XML Feeds

What is RSS?

Who's Online?

  • Guest Users: 5

powered by
b2evolution