mmap
| Use Case | Command | Description |
|---|---|---|
| Map a file read-only | m = mmap(fileno, length, access=ACCESS_READ) | Read-only memory mapping of a file descriptor |
| Map a file read-write | m = mmap(fileno, length, access=ACCESS_WRITE) | Read-write mapping, changes propagate to file |
| Create anonymous memory | m = mmap(-1, length) | Anonymous mapping (not backed by a file) |
| Flush modified pages | m.flush([offset, size]) | Write changes to the underlying file |
| Get file size | m.size() | Return the length of the file underlying the mapping |
| Read data from mapping | data = m.read(n) | Read up to n bytes as a string |
| Write data to mapping | m.write(data) | Write the bytes object to the mapping |
| Seek to a position | m.seek(pos, whence=0) | Set the file position for reading/writing |
| Find a substring | pos = m.find(sub, start=0, end=len(m)) | Return the lowest index where sub is found |
https://docs.python.org/3.10/library/mmap.html
The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.
Windows: mmap(fileno, length[, tagname[, access[, offset]]])
Maps length bytes from the file specified by the file handle fileno, and returns a mmap object. If length is larger than the current size of the file, the file is extended to contain length bytes. If length is 0, the maximum length of the map is the current size of the file, except that if the file is empty Windows raises an exception (you cannot create an empty mapping on Windows).
Unix: mmap(fileno, length[, flags[, prot[, access[, offset]]]])
Maps length bytes from the file specified by the file descriptor fileno, and returns a mmap object. If length is 0, the maximum length of the map will be the current size of the file when mmap is called. flags specifies the nature of the mapping. MAP_PRIVATE creates a private copy-on-write mapping, so changes to the contents of the mmap object will be private to this process, and MAP_SHARED creates a mapping that's shared with all other processes mapping the same areas of the file. The default value is MAP_SHARED.
To map anonymous memory, pass -1 as the fileno (both versions).
__delitem__(self, key, /) — Delete self[key].__enter__(...)__exit__(...)__getattribute__(self, name, /) — Return getattr(self, name).__getitem__(self, key, /) — Return self[key].__len__(self, /) — Return len(self).__repr__(self, /) — Return repr(self).__setitem__(self, key, value, /) — Set self[key] to value.close() — Close the mmap object.find(sub[, start[, end]]) — Return the lowest index in the object where substring sub is found.flush([offset, size]) — Flushes changes made to the in-memory copy of a file back to disk.madvise(option[, start[, length]]) — Give advice about the memory region.move(dest, src, count) — Copy the count bytes starting at offset src to the index dest.read([n]) — Return a bytes object containing up to n bytes starting from the current file position.read_byte() — Return a byte at the current file position as an integer.readline() — Return a single line, starting at the current file position and up to the next newline.resize(newsize) — Resize the map and the underlying file, if any.rfind(sub[, start[, end]]) — Return the highest index in the object where substring sub is found.seek(pos[, whence]) — Set the file's current position.size() — Return the length of the file, which may be larger than the size of the mapping.tell() — Return the current position of the file pointer.write(bytes) — Write the bytes object into memory at the current position and return the number of bytes written.write_byte(byte) — Write the integer byte into memory at the current position.__new__(*args, **kwargs) from builtins.type — Create and return a new object. See help(type) for accurate signature.closed — True if the mmap object is closed.ACCESS_COPY = 3ACCESS_DEFAULT = 0ACCESS_READ = 1ACCESS_WRITE = 2ALLOCATIONGRANULARITY = 4096MADV_DODUMP = 17MADV_DOFORK = 11MADV_DONTDUMP = 16MADV_DONTFORK = 10MADV_DONTNEED = 4MADV_FREE = 8MADV_HUGEPAGE = 14MADV_HWPOISON = 100MADV_MERGEABLE = 12MADV_NOHUGEPAGE = 15MADV_NORMAL = 0MADV_RANDOM = 1MADV_REMOVE = 9MADV_SEQUENTIAL = 2MADV_UNMERGEABLE = 13MADV_WILLNEED = 3MAP_ANON = 32MAP_ANONYMOUS = 32MAP_DENYWRITE = 2048MAP_EXECUTABLE = 4096MAP_POPULATE = 32768MAP_PRIVATE = 2MAP_SHARED = 1PAGESIZE = 4096PROT_EXEC = 4PROT_READ = 1PROT_WRITE = 2/usr/lib/python3.10/lib-dynload/mmap.cpython-310-x86_64-linux-gnu.so
Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-01 17:02 @216.73.216.239
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)