[Numpy-discussion] Views of memmaps and offset

Nathaniel Smith njs at pobox.com
Sun Sep 23 15:24:38 EDT 2012

On Sun, Sep 23, 2012 at 7:55 PM, Olivier Grisel
<olivier.grisel at ensta.org> wrote:
> 2012/9/23 Olivier Grisel <olivier.grisel at ensta.org>:
>> The only clean solution for the collapsed base of numpy 1.7 I see
>> would be to replace the direct mmap.mmap buffer instance from the
>> numpy.memmap class to use a custom wrapper of mmap.mmap that would
>> still implement the buffer python API but would also store the
>> filename and offset as additional attributes. To me that sounds like a
>> much cleaner than a "global scorecard of all extant memory mappings".
> Rather than a wrapper for mmap.mmap we could just subclass it actually.
> This is even cleaner: very few code change and would not break user
> code testing for `isintance(a.base, mmap.mmap)` or similar.

You'd need a subclass in either case, but the advantage of the "global
scorecard" (which would just be a sorted python list) is that in your
approach, you depend on all code everywhere passing around .base
values in the way you expect, but in my version the memmap pickle code
would only need to rely on a tiny bit of code that's maintained
alongside it in the same file. That's what I consider cleaner.


More information about the NumPy-Discussion mailing list