Advertisement
Fhernd

mapeo-memoria.py

Jul 10th, 2018
1,554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import os
  2. import mmap
  3.  
  4. def mapear_memoria(archivo, acceso=mmap.ACCESS_WRITE):
  5.     tamahnio = os.path.getsize(archivo)
  6.     apertura = os.open(archivo, os.O_RDWR)
  7.  
  8.     return mmap.mmap(apertura, tamahnio, access=acceso)
  9.  
  10.  
  11. tamahnio = 1000000
  12. with open('datos', 'wb') as f:
  13.     f.seek(tamahnio - 1)
  14.     f.write(b'\x00')
  15.  
  16.  
  17. m = mapear_memoria('datos')
  18. print(len(m))
  19. print(m[0:17])
  20.  
  21. m[0:17] =b'Python es genial!'
  22.  
  23. m.close()
  24.  
  25. with open('datos', 'rb') as f:
  26.     print(f.read(17))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement