Introduction
.NET inter-process mechanisms are very slow. With some system calls, it becomes easy to use file mapping and that's the faster mechanism for IPC.
Classes
MemMap
This class encapsulates a file mapping zone with system page-file support. All you need to do is give it a name and size.
Usage:
dim mem1 as MemMap=new MemMap("ZONE1",2048)
mem1.writeString(0,"String to share")
dim mem1 as MemMap=new MemMap("ZONE1",2048)
dim sharedString=mem1.readString(0)
mem1.close()
This class handles the creation or reuse of file mapping within the "new" method and has methods for reading and writing integers and strings on a given offset.
It gives also a locking function based on InterLockedExchanged with protection against process elimination while having holding a lock.
MemChannel
This class uses the MemMap class to implement a FIFO queue of strings. You can create any number of channels by simply giving different names to each one of them.
Usage:
dim cha1 as MemChannel=new MemChannel("CHANAME1")
cha1.putMsg("This is the message")
dim cha1 as MemChannel=new MemChannel("CHANAME1")
msgbox cha1.getMsg()
cha1.close()
EXEs
Points of interest
The sample programs included here runs at 250.000 msgs per second on a PIV 3 GHz. But they block each other while accessing the channel and the CPU is not 100% busy.
With MemMap class support, it becomes easy to implement other IPC mechanisms as shared Dictionaries.
History
- 25-06-2005 - First version.
- 20-01-2007 - Second version
| You must Sign In to use this message board. |
|
| | Msgs 1 to 12 of 12 (Total in Forum: 12) (Refresh) | FirstPrevNext |
|
 |
|
 |
Is there a way to read from a C++ program using this? I want to get a string from a program which has written to the memory using copymemory. I've tried using this library but returns the error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." in VB.net
Help please.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
The crash reported has ben fixed.
The locking mechanism has been replaced and performance boosts to 250.000 msg/s.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text ************** System.OutOfMemoryException: Channel:MSERVER Buffer Full at MClient.MemChannel.putmsgwait(String msg, Int32 timeout) at MClient.MClient.btnSendN_Click(Object sender, EventArgs e) at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies ************** mscorlib Assembly Version: 1.0.5000.0 Win32 Version: 1.1.4322.573 CodeBase: file:///d:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll ---------------------------------------- MClient Assembly Version: 1.0.2002.24080 Win32 Version: 1.0.2002.24080 CodeBase: file:///D:/Documents%20and%20Settings/Alex/Desktop/IPC/memmap/MemMap22/MemMap/MClient/bin/MClient.exe ---------------------------------------- System.Windows.Forms Assembly Version: 1.0.5000.0 Win32 Version: 1.1.4322.573 CodeBase: file:///d:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll ---------------------------------------- System Assembly Version: 1.0.5000.0 Win32 Version: 1.1.4322.573 CodeBase: file:///d:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll ---------------------------------------- System.Drawing Assembly Version: 1.0.5000.0 Win32 Version: 1.1.4322.573 CodeBase: file:///d:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll ---------------------------------------- Microsoft.VisualBasic Assembly Version: 7.0.5000.0 Win32 Version: 7.10.3052.4 CodeBase: file:///d:/windows/assembly/gac/microsoft.visualbasic/7.0.5000.0__b03f5f7f11d50a3a/microsoft.visualbasic.dll ----------------------------------------
************** JIT Debugging ************** To enable just in time (JIT) debugging, the config file for this application or machine (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled.
For example:
When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the machine rather than being handled by this dialog.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
The code is now corrected.
The locking mechanism has been replaced and performance boosts to 250.000 msg/s.
Please try again
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Maybe my article can help you make your code run a little faster.
http://www.codeproject.com/useritems/fast_ipc.asp[^]
This c++ IPC implementation does over 2,000,000 msg's per second.
I was thinking about writting my own C# implementation of the IPC method I presented but time was not on my side so I never did. Any how this should give you some ideas to accelerate yours.
John
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thanks for posting such a useful module. Is it OK if I use it in my commercial application? We'll make sure your name and a link to this website is clearly listed in the code so all our developers know what a help you've been.
- Brian
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
I didn't test it yet, but seems nice. It'd be interesting trying to write a Remoting channel over it (you just need to implement IChannel, IChannelSender and IChannelReceiver) to see if it can beat the TcpChannel.
I see dead pixels Yes, even I am blogging now!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
General
News
Question
Answer
Joke
Rant
Admin