Developer knowledge network · moderated exchange

مجتمع الكود غير الموثوق به

أبحاث المطورين، مجتمع الهندسة العكسية والترميز

Knowledge indexيعيش
4Categories
919Threads
2.8Kدعامات
Tutorial

High-Performance Zero-Copy Inter-Process Communication with MemoryMappedFiles in C# [StackOverflow Architecture Guide]

unsafe_memory_wizard
Unsafe & P/Invoke
MEMBER
مندوب: 160
تاريخ الانضمام: Jul 2022
دعامات: 10
شكرًا: 38
1 months ago · Jul 8, 2026 9:41 PM
#1

Sharing memory buffers between separate C# processes with microsecond latency:

CSHARP
// Process A (Writer)
using var mmf = MemoryMappedFile.CreateOrOpen("Global\\MySharedData", 1024 * 1024);
using var accessor = mmf.CreateViewAccessor();
accessor.Write(0, 42);

// Process B (Reader)
using var mmfReader = MemoryMappedFile.OpenExisting("Global\\MySharedData");
using var readerAccessor = mmfReader.CreateViewAccessor();
int value = readerAccessor.ReadInt32(0);

Both processes read and write directly to the same physical RAM page frame backed by the OS virtual memory manager!

dotnet_runtime_architect
.NET Core Specialist
MEMBER
مندوب: 103
تاريخ الانضمام: Apr 2018
دعامات: 40
شكرًا: 24
1 months ago · Jul 8, 2026 11:56 PM
#2

Memory mapped files provide the highest throughput possible for local IPC on Windows and Linux.

profiler_pat
Performance Hunter
MEMBER
مندوب: 146
تاريخ الانضمام: Aug 2019
دعامات: 33
شكرًا: 31
1 months ago · Jul 9, 2026 10:17 AM
#3

You can also obtain a byte* pointer via accessor.SafeMemoryMappedViewHandle.AcquirePointer for direct Span<T> wrapping!