Memory mapping is an alternative approach to file I/O that’s available to Python programs through the mmap
module. Memory mapping uses lower-level operating system APIs to store file contents directly in physical memory. This approach often results in improved I/O performance because it avoids many costly system calls and reduces expensive data buffer transfers.
In this video course, you learned:
- What the differences are between physical, virtual, and shared memory
- How to optimize memory use with memory mapping
- How to use Python’s
mmap
module to implement memory mapping in your code
The mmap
API is similar to the regular file I/O API, so it’s fairly straightforward to test out. Give it a shot in your own code to see if your program can benefit from the performance improvements offered by memory mapping.
To learn more about the concepts you covered in this course, check out:
- Python documentation: mmap — Memory-mapped file support
- Strings and Character Data in Python
- Speed Up Your Python Program With Concurrency
- Speed Up Python With Concurrency
- Learning Path: Python Concurrency & Parallel Programming
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
FooledByCode on June 23, 2022
Thanks for this refresher. It reminded me of good old days when I use to work heavily with C and RTOS. Would this be a good idea, if I read a csv file to train some Machine Learning model? What are your thoughts? What would be the Pros and Cons?