473,381 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 software developers and data experts.

memcpy

Tim
How do I memcpy from a pointer to an array of floats in python?

I get errors: NameError: global name 'row' is not defined

I want to be able to get the row[i] array element. In C I would
normally place the address of row as the first argument.

cdll.msvcrt.memcpy( row, pData, 256 )
If I define row as the following I also get the following error:

row = ones( TOTAL_PARAMETER_ENTRIES, dtype=float )

ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't know
how to convert parameter 1

Thanks

Sep 10 '07 #1
5 10926
On Mon, 10 Sep 2007 11:38:50 -0700, Tim wrote:
How do I memcpy from a pointer to an array of floats in python?

I get errors: NameError: global name 'row' is not defined
Well than the (global) name `row` is not defined. Quite clear message,
isn't it? ;-)
I want to be able to get the row[i] array element. In C I would
normally place the address of row as the first argument.

cdll.msvcrt.memcpy( row, pData, 256 )
If I define row as the following I also get the following error:

row = ones( TOTAL_PARAMETER_ENTRIES, dtype=float )

ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't know
how to convert parameter 1
You don't give enough information so we have to guess. For example I
guess the `ones()` function comes from one of the packages `numeric`,
`numarray` or `numpy`!?

This function returns a Python object. You can't use arbitrary Python
objects with `ctypes`. `memcpy` expects a pointer not an object.

Ciao,
Marc 'BlackJack' Rintsch
Sep 10 '07 #2
Tim
On Sep 10, 3:31 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Mon, 10 Sep 2007 11:38:50 -0700, Tim wrote:
How do I memcpy from a pointer to an array of floats in python?
I get errors: NameError: global name 'row' is not defined

Well than the (global) name `row` is not defined. Quite clear message,
isn't it? ;-)
I want to be able to get the row[i] array element. In C I would
normally place the address of row as the first argument.
cdll.msvcrt.memcpy( row, pData, 256 )
If I define row as the following I also get the following error:
row = ones( TOTAL_PARAMETER_ENTRIES, dtype=float )
ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't know
how to convert parameter 1

You don't give enough information so we have to guess. For example I
guess the `ones()` function comes from one of the packages `numeric`,
`numarray` or `numpy`!?

This function returns a Python object. You can't use arbitrary Python
objects with `ctypes`. `memcpy` expects a pointer not an object.

Ciao,
Marc 'BlackJack' Rintsch
Can I initialize something in Python that I can get access to it's
pointer?
How about:

self.data =
TOTAL_OUTPUT_PARMETERS*[TOTAL_PARAMETER_ENTRIES*[c_float()]

or

self.data = TOTAL_OUTPUT_PARMETERS*[c_char_p("temp")]

or

self.data = [TOTAL_OUTPUT_PARMETERS*1.0]*TOTAL_PARAMETER_ENTRIES

I need to be able to copy the contents of a pointer to shared memory
into an array of floats so I can index into that array and see my
data. I have a pointer to shared meory but I don't know how to access
it.

Here is what I would like to write:

shared_memory_pointer = windll.kernel32.MapViewOfFile(hMapObject,
FILE_MAP_ALL_ACCESS,
0, 0, TABLE_SHMEMSIZE)

memcpy( self.data, shared_memory_pointer, my_size )

Thanks

Sep 11 '07 #3
Tim a écrit :
<zip>
Can I initialize something in Python that I can get access to it's
pointer?
No, there is no pointer in Python semantic (they exist behind the scene
in C-Python).
How about:

self.data =
TOTAL_OUTPUT_PARMETERS*[TOTAL_PARAMETER_ENTRIES*[c_float()]

or

self.data = TOTAL_OUTPUT_PARMETERS*[c_char_p("temp")]

or

self.data = [TOTAL_OUTPUT_PARMETERS*1.0]*TOTAL_PARAMETER_ENTRIES

I need to be able to copy the contents of a pointer to shared memory
into an array of floats so I can index into that array and see my
data. I have a pointer to shared meory but I don't know how to access
it.
See module ctypes (14.14 in library reference manual).

A+

Laurent.
Sep 11 '07 #4
On Tue, 11 Sep 2007 05:09:58 -0700, Tim wrote:
On Sep 10, 3:31 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
>On Mon, 10 Sep 2007 11:38:50 -0700, Tim wrote:
How do I memcpy from a pointer to an array of floats in python?
I get errors: NameError: global name 'row' is not defined

Well than the (global) name `row` is not defined. Quite clear message,
isn't it? ;-)
I want to be able to get the row[i] array element. In C I would
normally place the address of row as the first argument.
cdll.msvcrt.memcpy( row, pData, 256 )
If I define row as the following I also get the following error:
row = ones( TOTAL_PARAMETER_ENTRIES, dtype=float )
ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't know
how to convert parameter 1

You don't give enough information so we have to guess. For example I
guess the `ones()` function comes from one of the packages `numeric`,
`numarray` or `numpy`!?

This function returns a Python object. You can't use arbitrary Python
objects with `ctypes`. `memcpy` expects a pointer not an object.

Can I initialize something in Python that I can get access to it's
pointer?
"It's pointer"? Then you have a pointer to a structure that represents
the Python object but still no idea what data is at that pointer. This is
an implementation detail of the Python version and of the particular
object.
Here is what I would like to write:

shared_memory_pointer = windll.kernel32.MapViewOfFile(hMapObject,
FILE_MAP_ALL_ACCESS,
0, 0, TABLE_SHMEMSIZE)

memcpy( self.data, shared_memory_pointer, my_size )
I haven't tested but it should be possible to declare the return type of
`windll.kernel32.MapViewOfFile()` as ``ctypes.POINTER(ctypes.c_double *
256)`` and then do:

test_data = numpy.ones(1000)
shared_memory_pointer.contents[0:256] = test_data[0:256]

Ciao,
Marc 'BlackJack' Rintsch
Sep 11 '07 #5
Tim
On Sep 11, 8:01 am, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Tue, 11 Sep 2007 05:09:58 -0700, Tim wrote:
On Sep 10, 3:31 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Mon, 10 Sep 2007 11:38:50 -0700, Tim wrote:
How do I memcpy from a pointer to an array of floats in python?
I get errors: NameError: global name 'row' is not defined
Well than the (global) name `row` is not defined. Quite clear message,
isn't it? ;-)
I want to be able to get the row[i] array element. In C I would
normally place the address of row as the first argument.
cdll.msvcrt.memcpy( row, pData, 256 )
If I define row as the following I also get the following error:
row = ones( TOTAL_PARAMETER_ENTRIES, dtype=float )
ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't know
how to convert parameter 1
You don't give enough information so we have to guess. For example I
guess the `ones()` function comes from one of the packages `numeric`,
`numarray` or `numpy`!?
This function returns a Python object. You can't use arbitrary Python
objects with `ctypes`. `memcpy` expects a pointer not an object.
Can I initialize something in Python that I can get access to it's
pointer?

"It's pointer"? Then you have a pointer to a structure that represents
the Python object but still no idea what data is at that pointer. This is
an implementation detail of the Python version and of the particular
object.
Here is what I would like to write:
shared_memory_pointer = windll.kernel32.MapViewOfFile(hMapObject,
FILE_MAP_ALL_ACCESS,
0, 0, TABLE_SHMEMSIZE)
memcpy( self.data, shared_memory_pointer, my_size )

I haven't tested but it should be possible to declare the return type of
`windll.kernel32.MapViewOfFile()` as ``ctypes.POINTER(ctypes.c_double *
256)`` and then do:

test_data = numpy.ones(1000)
shared_memory_pointer.contents[0:256] = test_data[0:256]

Ciao,
Marc 'BlackJack' Rintsch- Hide quoted text -

- Show quoted text -
Is this what you mean? Python did not like the word c_types in front
of POINTER. Do you know why? How can I re-declare a function's return
type if it is declared somewhere else?

test_data = numpy.ones(1000)
shared_memory_pointer = POINTER(c_float*256)
shared_memory_pointer =
windll.kernel32.MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS,
0, 0, TABLE_SHMEMSIZE)
test_data[0:256]= shared_memory_pointer.contents[0:256]

print 'data:', test_data[0]


Sep 11 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: franky.backeljauw | last post by:
Hello, following my question on "std::copy versus pointer copy versus member copy", I had some doubts on the function memcpy, as was used by tom_usenet in his reply. - Is this a c++ standard...
16
by: Delali Dzirasa | last post by:
I would have a number packed with its hex representation of the integer below is some sample code of what is being done. int value = 20; //in hex it is 0x14 AddData (value); .. .. ..
6
by: Samee Zahur | last post by:
Hi all, I'm a little confused - my guess is memcpy is no longer (or perhaps never was) a standard c++ function, since it has very little type check into it - and can potentially create havoc for...
5
by: manya | last post by:
Ok, it's been a while since I've done the whole memcpy stuff with C++ and I'm having a hard time remembering everything. I hope, however, that you can help me with my problem. I memcpy a...
35
by: Christopher Benson-Manica | last post by:
(if this is a FAQ or in K&R2, I didn't find it) What parameters (if any) may be 0 or NULL? IOW, which of the following statements are guaranteed to produce well-defined behavior? char src;...
16
by: Amarendra GODBOLE | last post by:
Hi, I am a bit confused over the correct usage of memcpy(). Kindly help me clear the confusion. The linux manpage for memcpy(3) gives me the following prototype of memcpy(3): #include...
33
by: Case | last post by:
#define SIZE 100 #define USE_MEMCPY int main(void) { char a; char b; int n; /* code 'filling' a */
6
by: myhotline | last post by:
hi all im very confused about using memcpy and i have three questions....memcpy takes a pointer to src and a pointer to dest and copies src to destination...but im very confuzed about when to...
18
by: Mark | last post by:
Hi List, I want to write a function to copy some data out of a hardware buffer. The hardware can change the contents of this buffer without it being written to by my function. I want to use...
18
by: sam | last post by:
(newbie)Technically what's the difference between memset() and memcpy() functions?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.