Memory mapping a file does not cause the entire file to be read into memory. In other words, the file is not copied into the memory cache or array. Instead, the operating system retains only a certain amount of virtual memory for the file contents. When you access different areas of a file, the contents of those areas are read and mapped to the memory area as needed. The ones that have never been accessed remain on disk.
Use the mmap () function to create a memory-mapped file. The first parameter is a file descriptor that can come from either a file object's Fileno () method or from Os.open (). The caller wants to open the file before calling Mmap () and closes it after the call finishes. The second parameter, in bytes, is the size of the mapping file. If the value is 0, the entire file is mapped. If it is larger than the current file size, the file is extended. The third optional parameter is access:access_read,access_write,access_copy.
Supports slicing to change file contents
Memory-mapped binaries in Python