Groups | Blog | Home
all groups > dotnet interop > december 2007 >

dotnet interop : accessing properties of object passed by an event, in a speedy manner


Joshua Waxman
12/30/2007 7:06:42 PM
Hello.

I'm working on a C++.NET project in which I am receiving events from a
COM object, using COM Interop. This is a time-critical application,
and Interop issues are slowing performance down to unacceptable
levels, and so I am looking for ways to optimize for speed.

This event is passing a structure, which I believe is a COM object
itself. This structure (or object) has about 20 public properties,
which I need to access. My questions are as follows:

1) When receiving such an object, what is taking the time? Is it the
initial receiving of the object, or (as I suspect) the accessing of
the properties, which presumably calls Get functions, and thus goes
through Interop? Or both?

2) Would it be faster to write a wrapper, such that rather than
passing an object and have to have repeated calls to access the
properties, it would have an event that would pass each of the
elements of the structure in turn? Or perhaps a single string,
containing all this data?

3) Is there some relatively straightforward way to access the actual
data in this structure, such that I could do a memcopy, rather than
having to access each of these properties in turn?

4) This is actually a C++.NET project which has parts which are
unmanaged. Is it possible to somehow put in the ActiveX control, and
event handler, in the unmanaged part, so as to avoid Interop there,
and later pass that to other parts of the code in the managed part?
(The slowdown is in accessing the ActiveX control, which has a single
thread, but if we could handle any data conversion in a separate
thread after we receive that data, it could speed things up.)

Thanks for any help in this matter.
Christian_Fröschlin
1/2/2008 10:24:51 AM
[quoted text, click to view]

What kind of effect are you experiencing, something
in the magnitude of a few ms per event or more?

[quoted text, click to view]

Try handling the event without reading the properties to find out.

[quoted text, click to view]

That should be possible.

[quoted text, click to view]

An STA thread? Note that you can get very painful performance
hits when you access the data object from another thread. This
AddThis Social Bookmark Button