Performance Question C++/CLI

S

Shawn B.

Greetings,

Lets say I have this class written in standard C++. I want to expose it to
C# programs. So lets say I create a ref class to "wrap" around the standard
C++ class. What are the performance implications of doing so?

For the sake of clarity, the class is currently written in C#. It is a CPU
emulator. C# performs well, but after rewriting it in C++/CLI it performs
even better. But I'd like to rewrite it in standard C++ and provide it to
..NET only through a wrapper. I won't be calling too many functions on the
object... just something like CPU cpu = gcnew ^CPU(); then cpu->Execute();
for the most part.

However, "Devices" plug into the CPU. So I can plug a display device to act
as a monitor and a keyboard device to act as a keyboard and a storage device
to act as something storage related. Since this is an old 8-bit and 16-bit
CPU (65c02 and 65816 to start with), these devices just specify what memory
locations they are monitoring and whether they are monitoring read/write
events or both.

The kicker is that, while the main application loop only calls
cpu->Execute() once, each device gets notified via delegates/function
callbacks. So, everything the CPU (or the memory manager mostly) needs to
notify something, there will be an unmanaged->managed interaction.

Can someone point out to me whether the performance implications are
(potentially) great enough that I'm better off continuing to keep in managed
code or what. Obvisously, I can try write it out and run tests to figure
this out for myself but I'd rather ask someone first, to get an idea what
I'm up against and whether its worthy my already stressed availably to do
so.


Thanks,
Shawn
 
B

Bruno van Dooren

The kicker is that, while the main application loop only calls
cpu->Execute() once, each device gets notified via delegates/function
callbacks. So, everything the CPU (or the memory manager mostly) needs to
notify something, there will be an unmanaged->managed interaction.

Can someone point out to me whether the performance implications are
(potentially) great enough that I'm better off continuing to keep in
managed code or what. Obvisously, I can try write it out and run tests to
figure this out for myself but I'd rather ask someone first, to get an
idea what I'm up against and whether its worthy my already stressed
availably to do so.

Hi,

I would like to give you a definite answer, but in the situation that you
describe, it all depends on the managed to unmanaged interation.

making the transition carries a certain overhead. If your native code is
faster than the managed code, this means that you can have n transitions per
second and be break even in performance.

if there are less than n transitions per second, you win. if there are more,
you lose.
The actual number depends on so many factors that there really is no other
way then to run some real performance tests.

I have seen situations where I won a serious performance gain. This was in
situations where some serious pointer arithmetic was done on large data
sets. We won because it was a large block of work that needed only 2
transitions to get it done.

I have also seen the opposite happen. It all depends on the amount of time
you win by going native versus the amount of time you lose by making the
transitions.

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 
S

Shawn B.

Hi,
I would like to give you a definite answer, but in the situation that you
describe, it all depends on the managed to unmanaged interation.

making the transition carries a certain overhead. If your native code is
faster than the managed code, this means that you can have n transitions
per second and be break even in performance.

if there are less than n transitions per second, you win. if there are
more, you lose.
The actual number depends on so many factors that there really is no other
way then to run some real performance tests.

I have seen situations where I won a serious performance gain. This was in
situations where some serious pointer arithmetic was done on large data
sets. We won because it was a large block of work that needed only 2
transitions to get it done.

I have also seen the opposite happen. It all depends on the amount of time
you win by going native versus the amount of time you lose by making the
transitions.

The CPU will spend the majority of its time operating on its own internall
memory structures. Only occasionally will it need to transition between
managed/unmanaged. I think, if you're typing, you can only type about 8
characters a second most of the time, so that's 8 transitions, meanwhile,
its executing 1 million instructions per second in its loop that aren't
transitioning. I don't have to make a callback when a graphics or text area
is updated with a new pixel or text character... if I'm refreshing the pages
50 times a second then the timer will handle it. It'll probly work out
pretty well in the end.


Thanks,
Shawn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top