Back to course

Memory Mapping (mmap)

Full Course: Zig Programming From Zero to Hero

Memory Mapping

For high-performance file access or shared memory, Zig provides access to mmap.

zig const file = try std.fs.cwd().openFile("large_file.bin", .{}); const size = (try file.stat()).size; const map = try std.os.mmap(null, size, std.os.PROT.READ, std.os.MAP.PRIVATE, file.handle, 0); defer std.os.munmap(map);