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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

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

StdRangesFan
Functional C++
MEMBER
Rep: 119
Join Date: Mar 2022
Posts: 6
Thanks: 79
2y ago · May 4, 2024 8:28 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.
StdRangesFan · Functional C++
C++20 view pipelines, lazy evaluation, and composable range algor...
The following users thanked StdRangesFan for this post:
MathEngineX
Game Physics & Math
MEMBER
Rep: 232
Join Date: Aug 2021
Posts: 6
Thanks: 107
2y ago · May 4, 2024 9:40 PM
#2
This allows querying gigabyte asset archives or level databases instantly using standard raw pointers without allocating megabytes of RAM upfront.
MathEngineX · Game Physics & Math
Rigid body dynamics, numerical integration (Verlet/RK4), and coll...
IntrinsicsNinja
AVX2 & NEON Intrinsics
MEMBER
Rep: 261
Join Date: Apr 2023
Posts: 6
Thanks: 56
2y ago · May 4, 2024 11:40 PM
#3
Don't forget to call UnmapViewOfFile / munmap and CloseHandle in your RAII wrapper destructor to prevent handle leaks.
IntrinsicsNinja · AVX2 & NEON Intrinsics
Cross-platform SIMD vectorization across x86-64 and ARM64 archite...