Marshalling in Same Process
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Marshalling in Same Process

  1. #1
    Join Date
    May 2009
    Location
    UK
    Posts
    10

    Question Marshalling in Same Process

    Hi,

    I have a VB COM client and an in-process COM object (VC++) both in the same STA. However, I need to add some asynchronous functionality to the COM object, creating worker threads to do concurrent processing. I am thinking that the COM object now has to be created in an MTA so that the asynchronous calls from the worker threads to the COM object are not serialised by the STA message queue. Is this correct?

    Also, if I now have an STA client making lots of calls to a COM object in the MTA, I am concerned that the marshalling overhead may negate any performance improvements I make by introducing multi-threading in my COM object. Is this likely if the inter-apartment calls are in the same process - is the marshalling overhead between apartments in the same process the same as marshalling between different processes?

    I am a bit stuck here, as I cannot rewrite the VB client so this has to stay an STA, and my COM object needs to be in an MTA to acheive multi-threading (the threads make calls to the COM object).

    Any ideas would be very helpful - thanks :-)

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: Marshalling in Same Process

    Marshalling within the same process uses LRPC, a light weight version of RPC that is designed for better performance than RPC. So it would definitely be much better in performance than an out-of-process call.

    If you are creating worker threads inside the COM component and the client doesn't need to know about it, you can still use STA.
    _Superman_
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Join Date
    May 2009
    Location
    UK
    Posts
    10

    Re: Marshalling in Same Process

    Thanks for your reply.

    My COM object creates worker threads that make asynchronous calls to another interface of the same COM object - I have assumed that this means I need to have the COM object in an MTA (and the worker threads)? If the COM object was in an STA, then the worker threads would have to join separate STAs since an STA can only have one thread. So, calls from the worker thread STAs to the COM obejct STA would be serialised by the COM STA message queue, negating my attempt to have asynchronous processing. Have I got this right or am I in a muddle?

  4. #4
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: Marshalling in Same Process

    This could be right the way you have put it.
    But I have one question.

    Since you are accessing one interface from the other in you COM component, why do you have to access it the COM way? Why not simply do it the C++ way?
    _Superman_
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  5. #5
    Join Date
    May 2009
    Location
    UK
    Posts
    10

    Re: Marshalling in Same Process

    My worker threads need to have access to the COM object and I have assumed that they cannot access the internal COM object and can only access it via an interface. This interface pointer will be passed to the thread functions. I need the worker threads to perform operations on the COM object in parallel.

    If there was another way I could do this, then that would be great?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center