memory position of numpy arrays

A. M. Archibald peridot.faceted at gmail.com
Tue Oct 24 02:21:21 EDT 2006


On 24/10/06, Lars Friedrich <lfriedri at imtek.de> wrote:

> I am not really sure about the term "locking". Does that mean that this
> part is not paged, or that this part is not accessed by two entities at
> the same time? Or both?

There are two kinds of locking, and really, you probably want both.
But mlock() just ensures that the virtual memory stays in actual RAM.

> Is my way a common way? I mean, letting python/numpy do the memory
> allocation by creating a numpy-array with zeros in and passing its
> memory location to the hardware-API?

It's not necessary to do it this way. I think a more usual approach
would be to create the buffer however is convenient in your C code,
then provide its address to numpy. You can then use the ndarray
function from python to tell it how to interpret that buffer as an
array. Since the C code is creating the buffer, you can make sure it
is in a special locked area of memory, ensure that the garbage
collector never comes calling for it, or whatever you like.

If you're having problems with driver stability, though, you may be
safest having your C code copy the buffer into a numpy array in one
shot - then you have complete control over when and how the DMA memory
is accessed. (In C, I'm afraid, but for this sort of thing C is
well-suited.)

A. M. Archibald

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the NumPy-Discussion mailing list