進程之間共享數據:C# SharedMemory

jopen 10年前發布 | 36K 次閱讀 .NET開發 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.

項目主頁:http://www.baiduhome.net/lib/view/home/1415065290831

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!