Quidest?

Python Storage VS Memory

ยท Lorenzo Drumond

Understanding the difference between storage (disk) and memory (RAM) is crucial. Memory operations are faster but volatile, while storage is persistent but slower. In performance-critical applications, keeping frequently accessed data in memory and minimising storage I/O is essential for speed.

Example:

1import mmap
2
3with open("data.txt", "r+b") as f:
4    mmapped_file = mmap.mmap(f.fileno(), 0)
5    print(mmapped_file.readline())
6    mmapped_file.close()

Memory-mapped files allow you to treat disk storage as if it were memory, speeding up access times for large files.

References

#storage #tricks #memory #python #tips #programming