[Mono-list] Fast Passing Strings to Interop without Marshaling

Chris Howie cdhowie at gmail.com
Mon Nov 3 13:03:45 EST 2008

On Mon, Nov 3, 2008 at 1:00 PM, Jonathan Pryor <jonpryor at vt.edu> wrote:
> On Mon, 2008-11-03 at 09:41 -0800, Bradford Stephens wrote:
>> I believe you still have to use the Marshaling in order to get an IntPtr.
> Yes, but marshaling an IntPtr doesn't require copying the entire buffer.
> Marshaling as a System.String *does* require copying the entire buffer.
> 4 bytes is clearly less than 100kB+. :-)
> So unless you really need a System.String, you could instead use IntPtr
> and use the System.Runtime.InteropServices.Marshal methods to interact
> with the unmanaged string, or you could use unsafe code and cast the
> IntPtr to a byte* for memory manipulation...

Of course, you'll have to represent the string as a short[] on the
unmanaged side.  If you want to convert string -> char[] then you're
going to have to copy the entire string character-by-character at some

Chris Howie

More information about the Mono-list mailing list