Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Buffer.BlockCopy? (memcpy equiv?)

Status
Not open for further replies.

Insider1984

Technical User
Feb 15, 2002
132
US
We are creating a C# app that needs to copy an image (or rather a (pointer + image size) to another memory location. Currently we are using IntPtr or byte* to do this in a for loop for each pixel. Apparently this is really slow compared to the old memcpy of the C++ C world.

A quick search finds that Buffer.BlockCopy seems to be the same style of function as memCpy. The problem is that it takes an Array not our current IntPtr.

Any advice on a faster approach?

Code:
//lock bits

            byte* outPtr = (byte*)outData.Scan0;
            byte* inPtr = (byte*)inputImagePointer;
            //Buffer.BlockCopy(inPtr, 0, outPtr, 0, (width * height));
            for (int i = 0; i < (width * height); i++)
            {
                *outPtr = *inPtr;
                outPtr++;
                inPtr++;
            }
//unlock bits

=====================
Insider
4 year 'on the fly' programmer
C, C++, C#, MFC, Basic, Java ASP.NET
 
Look into using the unsafe keyword, and then you can do stuff like this.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
we are currently unsafe but the issue that I'm unfamiliar with is the Buffer.BlockCopy needs Array and I'm using IntPointers.

This works but I need a faster approach.

Thanks for your input.

=====================
Insider
4 year 'on the fly' programmer
C, C++, C#, MFC, Basic, Java ASP.NET
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top