3

I want to send lot of strings (~250000) for <1sec from C application to a C# application. When I do it with WM_COPYDATA and SendMessage, my C# application hangs. What else can I do? Named pipes are included only in .NET 4, and I'm using .NET 2.

EDIT: I'm gonna stick to WM_COPYDATA and appending to a list (which is a fast operation). Then post processing this list.

blez
  • 4,939
  • 5
  • 50
  • 82
  • 1
    This SO question has information on using shared memory in .NET: http://stackoverflow.com/questions/439787/how-to-implement-shared-memory-in-net If the processes are on the same machine, it's hard to get much faster than that. – Michael Burr Aug 30 '11 at 16:21

3 Answers3

5

The fastest option is probably to use named pipes via P/Invoke. This is still much higher performance than most other IPC options.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • Not sure, but I think this code is buggy. It sends a few strings then stops (from the C application side) – blez Aug 30 '11 at 16:14
  • 1
    @blez: Make sure to read the comments at the bottom of that post - there are some flags for overlapped IO that are required to be set, which weren't in the original post... – Reed Copsey Aug 30 '11 at 16:23
4

Shared memory or MMF is the fastest method. It's as fast as kernel objects, used for signalling about data availability are. And, more importantly, you can first open the shared memory, then put your data directly there (saves you one copy operation) and signal to other application. That other application can consume the data directly from shared memory (again, no need to copy).

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
1

Not the fastest on win32 currently, but worth investigating: 0mq

Uses TCP sockets on Windows, but very efficiently.

For a closed source solution I don't think 29 West's Ultra Messaging can easily be trumped, includes a rare feature of zero-copy messaging in .net

Steve-o
  • 12,678
  • 2
  • 41
  • 60