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 5 10938
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
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
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.
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
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] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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);
..
..
..
|
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...
|
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...
|
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;...
|
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...
|
by: Case |
last post by:
#define SIZE 100
#define USE_MEMCPY
int main(void)
{
char a;
char b;
int n;
/* code 'filling' a */
|
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...
|
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...
|
by: sam |
last post by:
(newbie)Technically what's the difference between memset() and
memcpy() functions?
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |