Unmanaged Code switch - how much does it cost.

  • Thread starter Thread starter Mart Rogers
  • Start date Start date
M

Mart Rogers

We have been trying to avoid switches to unmanaged code in our development,
but have recently folded in a call to CDO by using System.Web.Mail as a
quick way to send email.

Yes this is a call to unmanaged code - but does anyone have any figures for
what that costs to do that switch?

How significant is a switch to unmanaged code (and back) bearing in mind
that it costs time to resolve the SMTP servers address and connecting to the
SMTP server.

Thanks in advance

Mart
 
per larsen said:
Mart,

In my experience, the execution overhead of an managed/unmanaged/managed
code switch by itself is only a fraction of a millisecond, so that
shouldn't cause any concern in your case. I guess if you were passing
lots of complex data (strings and such, which require special
marshaling) and did this a lot then the overhead could become
prohibitive, but it doesn't sounds like that's the case here.

Thanks for your reply.
 
Andrew Downum said:
The amount of time spent in a managed/unmanaged transition
will be totally dwarfed by anything that has to make a
network call. I don't have the exact number on hand, but
a simple managed-unmanaged function call with no
parameters ends up being somewhere on the order of a dozen
machine cycles, compared to a network request which could
easily end up in the multiple-millisecond range (or even
much longer on a latent network).

My general advice would be to write your app using the
most intuitive approach without stressing the performance
of every little call, and then run through your app with a
profiler and see just where the performance hotspots are.
I can almost guarentee that you will find much more
significant places to invest your optimization efforts
than managed/unmanaged transitions.

Thank you for your reply Andrew.
 
Back
Top