Home / Forums / How to write a custom Memory-Mapped File (mmap) reader in C++ [Part 5]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

How to write a custom Memory-Mapped File (mmap) reader in C++ [Part 5]

CmakeCraft
Build Systems Architect
MEMBER
Rep: 110
Join Date: Nov 2024
Posts: 6
Thanks: 21
6y ago · Jan 10, 2020 2:48 PM
#1
Memory-mapped I/O (CreateFileMapping / MapViewOfFile on Windows, mmap on POSIX) maps file contents directly into the process virtual address space. The OS page cache reads file pages on-demand with zero buffer copies.
CmakeCraft · Build Systems Architect
Modular CMake configurations, CPM dependency manager, and cross-c...
The following users thanked CmakeCraft for this post:
RingBufferRob
High-Speed IPC
MEMBER
Rep: 400
Join Date: Apr 2023
Posts: 6
Thanks: 43
6y ago · Jan 10, 2020 4:26 PM
#2
This allows querying gigabyte asset archives or level databases instantly using standard raw pointers without allocating megabytes of RAM upfront.
RingBufferRob · High-Speed IPC
Shared memory circular buffers with atomic sequence barriers acro...
StaticAssertDev
Compile-Time Verification
MEMBER
Rep: 275
Join Date: Dec 2025
Posts: 6
Thanks: 58
6y ago · Jan 11, 2020 5:26 PM
#3
Don't forget to call UnmapViewOfFile / munmap and CloseHandle in your RAII wrapper destructor to prevent handle leaks.
StaticAssertDev · Compile-Time Verification
Enforcing struct alignments, sizes, and invariant bounds via stat...