Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 10, 2018 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/b0421e651e453126798a370755290456 to your computer and use it in GitHub Desktop.
Save Fhernd/b0421e651e453126798a370755290456 to your computer and use it in GitHub Desktop.
Mapeo de memoria. OrtizOL.
import os
import mmap
def mapear_memoria(archivo, acceso=mmap.ACCESS_WRITE):
tamahnio = os.path.getsize(archivo)
apertura = os.open(archivo, os.O_RDWR)
return mmap.mmap(apertura, tamahnio, access=acceso)
tamahnio = 1000000
with open('datos', 'wb') as f:
f.seek(tamahnio - 1)
f.write(b'\x00')
m = mapear_memoria('datos')
print(len(m))
print(m[0:17])
m[0:17] =b'Python es genial!'
m.close()
with open('datos', 'rb') as f:
print(f.read(17))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment