

(You might remember that when you bought your computer, it advertised something like 8 gigabytes of RAM.) Physical memory typically comes on cards that are connected to your computer’s motherboard. Physical memory is the least complicated type of memory to understand because it’s often part of the marketing associated with your computer. There are several types of computer memory:Įach type of memory can come into play when you’re using memory mapping, so let’s review each one from a high level.

For the purposes of this tutorial, the term memory refers to random-access memory, or RAM. To better understand how memory mapping improves performance, as well as how and when you can use the mmap module to take advantage of these performance benefits, it’s useful to first learn a bit about computer memory.Ĭomputer memory is a big, complicated topic, but this tutorial focuses only on what you need to know to use the mmap module effectively. It can dramatically improve file I/O performance in your program. Memory mapping is a technique that uses lower-level operating system APIs to load a file directly into computer memory. How to use mmap to share information between multiple processesįree Download: Get a sample chapter from CPython Internals: Your Guide to the Python 3 Interpreter showing you how to unlock the inner workings of the Python language, compile the Python interpreter from source code, and participate in the development of CPython.


For example, there are multiple ways to read a file in Python, including the rarely used mmap module. One especially useful idea is that “There should be one-and preferably only one-obvious way to do it.” Yet there are multiple ways to do most things in Python, and often for good reason. The Zen of Python has a lot of wisdom to offer. Watch it together with the written tutorial to deepen your understanding: Python mmap: Doing File I/O With Memory Mapping Watch Now This tutorial has a related video course created by the Real Python team.
