[Ironpython-users] Memory Allocation in Iron Python

Jeff Hardy jdhardy at gmail.com
Mon Jan 23 22:30:06 CET 2012


There are a couple of known bugs in ctypes. Can you produce a
self-contained example, perhaps using a libc on Windows API function
as the target?

- Jeff

On Sun, Jan 22, 2012 at 3:50 PM, Jim Pattee <jimp02 at email.com> wrote:
> 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
> Ironpython-users at python.org
> http://mail.python.org/mailman/listinfo/ironpython-users
>


More information about the Ironpython-users mailing list