进程之间共享数据:C# SharedMemory
C# shared memory classes 用于进程之间共享数据 (Array, Buffer and Circular Buffer)。封装了 .NET 4 的 MemoryMappedFile 用于实现快速低级的 IPC 进程间通讯。特别是用于进程间的数据共享。
提供的类库包括
- SharedMemory.Buffer - an abstract base class that wraps the .NET 4 MemoryMappedFile class, exposing the read/write operations and implementing a small header to allow clients to open the shared buffer without knowing the size beforehand.
- SharedMemory.BufferWithLocks - an abstract class that extends SharedMemory.Buffer to provide simple read/write locking support through the use of EventWaitHandles.
- SharedMemory.Array - a simple generic array implementation utilising a shared memory buffer. Inherits from SharedMemory.BufferWithLocks to provide support for thread synchronisation.
- SharedMemory.BufferReadWrite - provides read/write access to a shared memory buffer, with various overloads to support reading and writing structures, copying to and from IntPtr and so on. Inherits from SharedMemory.BufferWithLocks to provide support for thread synchronisation.
- SharedMemory.CircularBuffer - lock-free FIFO circular buffer implementation (aka ring buffer). Supporting 2 or more nodes, this implementation supports multiple readers and writers. The lock-free approach is implemented using Interlocked.Exchange and EventWaitHandles as explained here.
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!