Hi David,
I see your problem. Of course there is the marshaling overhead when calling
into .NET and passing array's (SafeArray) from COM to the CLR. The major
overhead is due to the copying (memcpy) of the array to a managed array
reference type, the cost of marshaling back into COM is less important.
To give you an idea, marshaling a 20000 elem. Array of double's takes
~250µsec[*]. When using copy-in semantics (SomeMethod([In] arg...))
And ~300µsec when using copy in/out semantics ( SomeMethod([In, Out]
arg...))
You can reduce this call overhead to something like 20-30 µsec. when passing
a pointer to a C style array from COM to .NET in an unsafe context. Of
course this restrict you to use C++ as your COM components implementation
language, and because C style array's are not self describing, you have to
pass the size of the array as argument too.
For instance ...
unsafe public void SomeMethod([In, Out]double* dar, int al)
{ // use array indexed syntax to access elements
dar[n] = ...;
Now all depends on the service time (the time spent in the called method),
is this one is large compared to the marshaling time, you won't take much
advantage of pointer marshaling, however, if the call time is small and the
number of calls is high you can effectively reduce the call overhead by
using pointer marshaling.
Willy.
[*] PS the performance figures are those measured on a 3 Ghz P4 system
running XP SP2, you mileage may vary.
"apm" <Co*********@AdsorptionProcessModeling.com> wrote in message
news:b2FWe.11759$nq.4936@lakeread05...
You can ONLY do this with non-reference types though. Doing it on a
reference type would be pointless, since the marshaller has to marshal
the .NET reference to an unmanaged thunk that unmanaged code can work
with.
Hope this helps.
Great help. Thank you. Will you offer further enlightenment on the subject
of what happens with reference types? This seems like it may be a bigger
problem.
If .NET would copy only once and use the copy in subsequent calls there
would be no problem. The problem I have is that a number of COM objects
were developed that support methods that may be called many thousands of
times before a run is complete. At one time the plan was to do future
development using .NET. Unfortunately the code took significantly (very,
very) longer to run when COM and .NET components were mixed.
David
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"apm" <Co*********@AdsorptionProcessModeling.com> wrote in message
news:LlEWe.11756$nq.8691@lakeread05... Any and all:
Is there an efficient way to pass a large array from .NET to COM? Can
references (or pointer) be passed from COM to NET and NET to COM without
the object it refers to being copied?
Thanks in advance.
David