Created
July 10, 2018 12:35
-
-
Save Fhernd/b0421e651e453126798a370755290456 to your computer and use it in GitHub Desktop.
Mapeo de memoria. OrtizOL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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