473,378 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Copying data from unmanaged buffer to local array

I'm trying to copy data from an array that's created and filled by an
external DLL into a local managed array. The basics are something like:

ushort[,] localArray = new ushort[columns, rows];
IntPtr unmanagedBuffer = IntPtr.Zero;

// Note: I can't pass in a pointer to my array.
// The DLL creates its own buffer which it passes back.
// Image size is set through other commands.
Controller.AllocateBuffer(Device, ref unmanagedBuffer);

// This command would actually store the image in the buffer pointed to
// by unmanagedBuffer
Controller.ReadImage(Device, imageNumber);
I then want to copy the array from the unmanagedBuffer to the
localArray. I can do this at present by looping through the array
elements and doing a Marshal.ToInt16 on each one, but speed has become a
major factor. It takes 3 ms to complete the ReadImage function, but 750
ms to complete a looped copy, and that's just way too long (300 frames
would take about 1 second to read, but almost 4 minutes to copy).

I've tried to figure out how to just use Marshal.Copy for this, but it
always tends to run into some exception. Is there a way to do the
equivalent of a fast memcpy here?

--
David
Nov 16 '05 #1
0 1080

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have...
1
by: LongBow | last post by:
Hello, I am attempting to create an application that uses an existing driver interface API using C#. I have an API that looks like F32x_Read( HANDLE Handle, LPVOID Buffer, DWORD...
3
by: Marauderz | last post by:
Hi there, Got a quick question, I have an app that I'm compiling with /clr and I have a native function that passes in a pointer, and I need to copy from that unmanaged memory into a managed...
0
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.