From: StevO on
BitBlt'ing from unmanaged memory into an hDC obtained in a managed
(C#) program takes 50-100% longer than the same BitBlt into an hDC
obtained in an unmanaged (old VB6) program.

My ShowPic() function resides in a DLL written in straight C.
It reads a JPEG into memory allocated within the unmanaged DLL and
then StretchDIBits()s it to the hDC passed.

Some ancient VB6 code called it in a Paint event:

Private Sub Picture1_Paint()
ShowPic(Picture1.hdc, ...)
End Sub

Here is the C# code that is almost 100% slower:

private void picObj1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Graphics gfx = e.Graphics;
IntPtr pTarget = gfx.GetHdc();
ShowPic(pTarget, ...);
gfx.ReleaseHdc(pTarget);
}

I simplified the example code above but would be glad to provide more
detail.

WHAT IS SLOWING IT DOWN... and how can I speed it back up?

From: Peter Duniho on
StevO wrote:
> [...]
> Here is the C# code that is almost 100% slower:
>
> private void picObj1_Paint(object sender,
> System.Windows.Forms.PaintEventArgs e)
> {
> Graphics gfx = e.Graphics;
> IntPtr pTarget = gfx.GetHdc();
> ShowPic(pTarget, ...);
> gfx.ReleaseHdc(pTarget);
> }
>
> I simplified the example code above but would be glad to provide more
> detail.
>
> WHAT IS SLOWING IT DOWN... and how can I speed it back up?

It could easily be the interop overhead, which involves marshaling of
data types that AFAIK would not be required in the VB6 program. There
also is the question of retrieving the DC. Not that I'd expect that to
be _very_ slow, but there may be subtle differences between getting the
DC in your VB6 code (especially if that's an "owner DC"�one created
permanently for the window) as compared to retrieving the DC from the
Graphics instance.

But yes, a concise-but-complete code example would be required for any
specific statements to be made about what's actually slowing things down.

Pete
 | 
Pages: 1
Prev: Hyperaccess using C#
Next: Where : class { ... }