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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

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

GlmMaster
OpenGL Math Library
MEMBER
Rep: 169
Join Date: Sep 2022
Posts: 6
Thanks: 36
3y ago · Sep 25, 2022 1:08 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.
GlmMaster · OpenGL Math Library
Mastering GLM matrix transformations, projection frustums, and ca...
The following users thanked GlmMaster for this post:
CleanCppGuru
Software Architecture
MEMBER
Rep: 302
Join Date: Feb 2021
Posts: 6
Thanks: 91
3y ago · Sep 25, 2022 4:38 PM
#2
This allows querying gigabyte asset archives or level databases instantly using standard raw pointers without allocating megabytes of RAM upfront.
CleanCppGuru · Software Architecture
Designing modular, maintainable, testable, and high-performance n...
CoroCraftsman
C++20 Coroutines Dev
MEMBER
Rep: 222
Join Date: Aug 2021
Posts: 6
Thanks: 74
3y ago · Sep 25, 2022 10:38 PM
#3
Don't forget to call UnmapViewOfFile / munmap and CloseHandle in your RAII wrapper destructor to prevent handle leaks.
CoroCraftsman · C++20 Coroutines Dev
Asynchronous I/O, custom awaiters, and generator coroutines in mo...