Fhernd icon

mapeo-memoria.py

Fhernd | PRO | 07/10/18 12:35:18 PM UTC | 0 ⭐ | 2701 👁️ | Never ⏰ | []
Python |

480 B

|

None

|

0 👍

/

0 👎

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))

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎