简体   繁体   中英

what is fastest way for Visual-C++ DLL to copy 2-3Mega-Bytes to a C# buffer?

And what kind of C# buffer can handle this?

I need my C# solution .exe to get about 2-3MB of data, up to 60 times a second, from a Visual-C++ DLL that is generating live video frames (up to 60/second) and copying it to the C# buffer. C# will then forward this data through USB to another computer.

I've tried C# String but there's a maximum size limit (roughly around 10KB).

I'm thinking of a C# struct containing the data buffer plus handshake variables.

Possibly, I will need multiple buffers, so maybe will need an array of these structs.

But, essentially, what's the best way (fastest!!!) to give DLL destination address of some kind of C# buffer, so that DLL can copy its 2-3MB of generated data to the buffer, and then set a variable flag, meanwhile C# is polling this flag to know when data is in buffer, so it can be further processed.

Buffer should be first created by C#, not DLL, I think.

Here is an idea:

  1. Have the C# code allocate the buffer
  2. Pin it to a fixed address
  3. Pass the pointer to the C++ code
  4. The C++ code can now directly write to the buffer (maybe even using a zero-copy approach)

Advantage is that you can use a normal, managed byte[] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM