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
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.