[Numpy-discussion] How to access to the start of a mmaped numarray object?

Francesc Alted falted at openlc.org
Thu Oct 16 05:06:20 EDT 2003


Hi,

While dealing with memory mapped numarray objects, I'm having some problems
to access to the address where the data starts. For normal (i.e. no
memory-mapped) objects, I normally used this:

    PyObject_AsReadBuffer(recarr._data, &self.rbuf, &buflen)

that works fine, but after creating a RecArray associated to a memory mapped
file in the normal way, i.e.:

    self.mmfile = memmap.Memmap("prova.out",mode="r")
    recarr = records.RecArray(self.mmfile[:],
                              formats=self.description._v_recarrfmt,
                              shape=self.totalrecords)

then, I'm unable to use the PyObject_AsWriteBuffer anymore. I've tried the
following:

    PyObject_AsReadBuffer(recarr._data, &self.mmrbuf, &buflen)
    (this returns a -1, failed, value)
    
    PyObject_AsReadBuffer(recarr._data._buffer, &self.mmrbuf, &buflen)
    (this produces a segmentation fault)

    PyObject_AsReadBuffer(recarr._data.__buffer__(), &self.mmrbuf, &buflen)
    (another seg fault)

Of course, I've checked out that the recarr object is sane (i.e. it has the
same data than the file). Any hint?

-- 
Francesc Alted





More information about the NumPy-Discussion mailing list