Developer knowledge network · moderated exchange

Супольнасць UnreliableCode

Супольнасць распрацоўшчыкаў даследаванняў, зваротнага праектавання і кадавання

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 месяцаў таму · 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 месяцаў таму · 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 месяцаў таму · Jul 9, 2026 10:17 AM
#3

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