1

I have a c# application where I am reading data from the network into a fixed buffer. However, I do not create the fixed buffer. The buffer is passed to me as an unmanaged memory block (IntPtr). The Socket.Receive method only accepts byte[] or ArraySegments of byte to read into.

The easiest method is to just read data into a temp buffer and copy that data into the unmanaged block, but after having done this, the application uses ~25% more cpu just doing memory copies.

Is there any way I can pass the unmanaged block into the Socket Read and avoid doing the extra memcopy?

Dabloons
  • 1,462
  • 2
  • 17
  • 30
  • 2
    This is an XY problem. A fast network adapter that runs at 1 Gb/sec is easily 300 times slower than the memory bus bandwidth. Burning 25% core is a coding mistake. We can't see your code. – Hans Passant Aug 08 '14 at 17:37
  • How are you doing the memory / buffer copy? My guess is that there is a better way. – Haney Aug 08 '14 at 17:47
  • possible duplicate of [How can I in C# stream.Read into unmanaged memory stream?](http://stackoverflow.com/questions/1367350/how-can-i-in-c-sharp-stream-read-into-unmanaged-memory-stream) – Abdullah Saleem Aug 08 '14 at 18:46

0 Answers0