[Mono-list] Fast Passing Strings to Interop without Marshaling
Bradford Stephens
bradfordstephens at gmail.com
Mon Nov 3 13:17:07 EST 2008
The String is actually an XML document in memory, so byte-level
manipulation isn't very useful. However, if we just used a byte* to
get 'past the barrier', then re-converted it in C to a char* (where
the code is faster), perhaps that would work?
On Mon, Nov 3, 2008 at 10:03 AM, Chris Howie <cdhowie at gmail.com> wrote:
> 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
> point.
>
> --
> Chris Howie
> http://www.chrishowie.com
> http://en.wikipedia.org/wiki/User:Crazycomputers
>
More information about the Mono-list
mailing list