C ++ / CLI Mixed Mode Best Practices

I have a C ++ / CLI library that calls many native C ++ methods. I've read a lot of topics that say you shouldn't mix managed and unmanaged code. I couldn't find anything that says how to avoid these switches and why it would cause a performance issue. Can anyone share some best practices.

+1


source to share


1 answer


The only reason to use C ++ / CLI is to support mixing managed and native code. If everything is managed then use C # or VB, if everything is native then use C or C ++. Or whatever language you prefer. Obviously, avoiding mixing is pointless.



There is a small amount of overhead, from managed to unmanaged. The C ++ / CLI compiler automatically generates a bit of machine code that pushes the cookie onto the stack, designed to prevent the garbage collector from crashing on unmanaged stack frames and misinterpreting pointers on that frame as managed object references. Costs about 7 nanoseconds, give or take.

+3


source







All Articles