Developer knowledge network · moderated exchange

Społeczność UnreliableCode

Badania programistów, inżynieria wsteczna i społeczność programistów

Knowledge indexNa żywo
4Categories
919Threads
2.8KPosty
Tutorial

High-Speed Memory Mapped Files (CreateFileMapping) for Zero-Copy IPC

ptr_arithmetic
C++ Wizard
MEMBER
Rozpustnik: 162
Data dołączenia: May 2018
Posty: 73
Dzięki: 42
1 miesięcy temu · Jul 10, 2026 2:39 AM
#1

Instead of slow TCP sockets or named pipes for communicating between a background reader and frontend UI:

CPP
// Server / Reader process
HANDLE hMapFile = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, sizeof(SharedGameState), "Local\\GameOverlayData");
SharedGameState* pShared = (SharedGameState*)MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(SharedGameState));

// Client / Overlay process
HANDLE hMapFile = OpenFileMappingA(FILE_MAP_READ, FALSE, "Local\\GameOverlayData");
const SharedGameState* pShared = (const SharedGameState*)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, sizeof(SharedGameState));

Both processes read and write to the exact same physical RAM pages mapped into virtual memory. Latency is literally 0 nanoseconds (direct RAM read)!

imgui_artisan
UI Designer
MEMBER
Rozpustnik: 202
Data dołączenia: Apr 2019
Posty: 54
Dzięki: 28
1 miesięcy temu · Jul 10, 2026 7:34 AM
#2

Shared memory mapped files are unbeatable for multi-process overlays. Pair with an alignas(64) std::atomic<uint32_t> frameIndex to synchronize frames.

vtable_slayer
Senior Reverser
MEMBER
Rozpustnik: 215
Data dołączenia: Mar 2018
Posty: 86
Dzięki: 61
1 miesięcy temu · Jul 11, 2026 1:26 AM
#3

Clean Win32 API usage.