How to use a contiguous memory location of n bytes in python
nick at craig-wood.com
Fri Nov 14 14:29:58 CET 2008
bearophileHUGS at lycos.com <bearophileHUGS at lycos.com> wrote:
> > I want to know how to instantiate a data structure which has n bytes
> > (given by me) and is internally stored in a contiguous fashion.
> array.array("B", ...) may be fit for you. You can also use a numpy
> array of bytes.
The mmap module is useful also for larger amounts (>4k say).
mmap's are individually free-able so they don't fragment your memory.
Eg create a 1 GB anonymous mmap, access it and then delete it
>>> from mmap import mmap
>>> a = mmap(-1, 1000000000)
>>> a = 'z'
>>> del a
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick
More information about the Python-list