Memory-mapped binaries in Python

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.