diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2009-04-12 23:32:41 +0000 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2009-04-12 23:32:41 +0000 |
commit | d673c50ccfe30f0b97de2d853e20fdc191a3fe30 (patch) | |
tree | a47ea60820aee718832829d245efecd75f933528 /numpy/core/memmap.py | |
parent | 2fbfbcf3ec688539f7dd30e0a3afafa7929b213b (diff) | |
download | numpy-d673c50ccfe30f0b97de2d853e20fdc191a3fe30.tar.gz |
Fix memmap for python >= 2.6 by making offset multiple of
ALLOCATIONGRANULARITY.
Diffstat (limited to 'numpy/core/memmap.py')
-rw-r--r-- | numpy/core/memmap.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index 05bfd68b7..5c8542479 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -226,14 +226,16 @@ class memmap(ndarray): if sys.version_info[:2] >= (2,6): # The offset keyword in mmap.mmap needs Python >= 2.6 - bytes = bytes - offset - mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=offset) - self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm, - offset=0, order=order) + blocks = offset // mmap.ALLOCATIONGRANULARITY + aligned_offset = blocks * mmap.ALLOCATIONGRANULARITY + bytes = bytes - aligned_offset + offset = offset - aligned_offset + mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=aligned_offset) else: mm = mmap.mmap(fid.fileno(), bytes, access=acc) - self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm, - offset=offset, order=order) + + self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm, + offset=offset, order=order) self._mmap = mm return self |