[Ironpython-users] Memory Allocation in Iron Python

2012-01-22 Thread Jim Pattee
I am trying to allocate memory in Iron Python to receive text from a DLL. The 
allocated memory address is passed to the DLL and the text is copied by the DLL 
into the memory area. The following code, which works in CPython, is used:
allocated =[]
def MemoryAllocation(size):
arr_type = c_char * size# create a c_char array
arr_obj = arr_type()# create an array object
allocated.append(arr_obj)# so the object will not be destroyed
if len(allocated)> 1:# free memory for the previous object
del allocated[0]
return addressof(arr_obj)# return a pointer
When this is used for Iron Python it results in:
“Unhandled Exception: System.AccessViolationException: Attempted to read or 
write
protected memory. This is often an indication that other memory is corrupt.”
The error results when the memory is copied into Python by the DLL. There are 
no errors displayed when executing the above code.
Why can it not write to the memory? What is the difference in Iron Python and 
CPython?
___
Ironpython-users mailing list
[email protected]
http://mail.python.org/mailman/listinfo/ironpython-users


Re: [Ironpython-users] Memory Allocation in Iron Python

2012-01-22 Thread Markus Schaber
Hi, Jim,

You only gave us half of the source. Which way do you pass the memory address 
to the native DLL?

One difference is, for example, that .NET relocates objects sometimes, so they 
need to be pinned.

Best regards

Markus Schaber
--
___
We software Automation.

3S-Smart Software Solutions GmbH
Markus Schaber | Developer
Memminger Str. 151 | 87439 Kempten | Germany | Tel. +49-831-54031-0 | Fax 
+49-831-54031-50

Email: [email protected] | Web: 
http://www.3s-software.com 
CoDeSys internet forum: 
http://forum.3s-software.com
Download CoDeSys sample projects: 
http://www.3s-software.com/index.shtml?sample_projects

Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade 
register: Kempten HRB 6186 | Tax ID No.: DE 167014915

Von: [email protected] 
[mailto:[email protected]] Im 
Auftrag von Jim Pattee
Gesendet: Montag, 23. Januar 2012 00:50
An: [email protected]
Betreff: [Ironpython-users] Memory Allocation in Iron Python

I am trying to allocate memory in Iron Python to receive text from a DLL. The 
allocated memory address is passed to the DLL and the text is copied by the DLL 
into the memory area. The following code, which works in CPython, is used:
allocated = []
def MemoryAllocation(size):
 arr_type = c_char * size# create a c_char array
 arr_obj = arr_type()# create an array object
 allocated.append(arr_obj)   # so the object will not be destroyed
 if len(allocated) > 1:  # free memory for the previous object
  del allocated[0]
 return addressof(arr_obj)   # return a pointer

When this is used for Iron Python it results in:
“Unhandled Exception: System.AccessViolationException: Attempted to read or 
write
protected memory. This is often an indication that other memory is corrupt.”

The error results when the memory is copied into Python by the DLL. There are 
no errors displayed when executing the above code.

Why can it not write to the memory? What is the difference in Iron Python and 
CPython?

___
Ironpython-users mailing list
[email protected]
http://mail.python.org/mailman/listinfo/ironpython-users