<html>
<body>
Thanks Todd, Travis,<br><br>
Yes, Travis, I _was_ using ctypes' memmove() with numarray to great
benefit. I had also understood that the address of the numarray data was
stable.<br><br>
Originally, I was trying to move data from a hardware A/D driver DLL call
to Python as quickly as possible and did some benchmarking, so as per
Thomas Heller's suggestion on the ctypes list I used memmove():<br>
<a href="http://sourceforge.net/mailarchive/forum.php?thread_id=6166311&forum_id=24606" eudora="autourl">http://sourceforge.net/mailarchive/forum.php?thread_id=6166311&forum_id=24606</a><br>
<pre> from ctypes import *
 import array 
 src = array.array("i", range(32))
 dst = (c_int * 32)()
 memmove(dst, *src.buffer_info())
</pre>memmove() is orders of magnitude faster than map() or
assignments.<br>
I then tested and found numarray faster for the rest of the tasks (FFT
etc.)
<a href="http://sourceforge.net/mailarchive/forum.php?thread_id=6205658&forum_id=24606" eudora="autourl">http://sourceforge.net/mailarchive/forum.php?thread_id=6205658&forum_id=24606</a><br>
and so parsed the info() output and plugged the data[0] address into the
call.<br><br>
Thomas Heller (in the above) suggested he make a mod to ctypes to accept
Python objects which implement the buffer interface as function
parameters, which would allow Numeric use once implemented.<br>
I like numarray's breadth of methods so I used it at the time, but in
another try at speed-squeezing yesterday afternoon I found Numeric's FFT
and subtraction to be >30% faster in this case, so I switched that
code over (this increase includes the use of map() with Numeric to read
the A/D in another thread). Using memmove() with Numeric would speed up
the reader thread once again.<br><br>
At 08:06 AM 2/1/2005 -0500, Todd Miller wrote:<br>
<blockquote type=cite class=cite cite>> <br>
> What is the actual address of the first element? <br><br>
In C,  look at a->data.</blockquote><br>
I had read the Numeric API and looked at the PyObject structure, as
Travis then suggested, but my question then is: if the offset from the
"array object at 0x..." (object address value) to the array[0]
address is not fixed and must be read from the pointer in the PyObject
structure, can we get that pointer's value directly from Python or
ctypes? <br>
ctypes pointer() "allows" poking in and directly reading
memory: <br>
"It is also possible to use indexes different from 0, but you must
know what you're doing when you use this: You access or change arbitrary
memory locations when you do this."<br>
<a href="http://starship.python.net/crew/theller/ctypes/tutorial.html" eudora="autourl">http://starship.python.net/crew/theller/ctypes/tutorial.html</a><br>
So, could I use ctypes' pointer(offset) to read the structure's
pointer-to-data[0]-value and then use it in memmove()? <br>
I'll cross-post this to ctypes-users...<br><br>
<blockquote type=cite class=cite cite>I think the "fragile data
pointer" is generally useful information,  but<br>
not completely dependable so I gave it the garish name it has.<br>
Comments?</blockquote><br>
It's quite reasonable. <br>
Is the data pointer value really often changed for contiguous arrays in
small stand-alone Python apps? If so, I may stick with map() to avoid
having to re-read the pointer before each data buffer transfer.<br><br>
If anyone is interested I could post some relevant code snips from the
office...<br><br>
Thanks for the help,<br>
Ray<br>
</body>
</html>