5

I have a python method that returns a Python byte array.array('c').

Now, I want to copy this array using System.Runtime.InteropServices.Marshal.Copy. This method however expects a .NET array.

import array
from System.Runtime.InteropServices import Marshal

bytes = array.array('c')
bytes.append('a')
bytes.append('b')
bytes.append('c')
Marshal.Copy(bytes, dest, 0, 3)

Is there a way to make this work without copying the data? If not, how do I convert the data in the Python array to the .NET array?

1 Answer 1

7

To convert a python array to a .NET Array:

import array
from System import Array, Char

x = array.array('c', 'abc')

y = Array[Char](x)

Here is some information on creating typed Arrays in IronPython: http://www.ironpython.info/index.php?title=Typed_Arrays_in_IronPython

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for responding. I already got a resolution to my marshaling issue on the IronPython newgroup (groups.google.com/group/ironpy/t/91a344a5ddb7df39)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.