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

Alan McGovern alan.mcgovern at gmail.com
Mon Nov 3 03:55:37 EST 2008


What would happen if you passed the string as an IntPtr type rather than a
char* type?

Alan.

On Mon, Nov 3, 2008 at 8:29 AM, Chris Howie <cdhowie at gmail.com> wrote:

> On Mon, Nov 3, 2008 at 2:48 AM, Bradford Stephens
> <bradfordstephens at gmail.com> wrote:
> > We're passing very large strings to a C program in Linux through Mono
> > via Interop. The C program takes a (char*), and our C# program uses a
> > String.
> >
> > The problem is that these strings can be 100kB+, and there seems to be
> > a large performance impact. Often, just passing the string along takes
> > over 150 milliseconds.
> >
> > Any suggestions on how to do this faster? Can I pass a reference to
> > the string or some sort of char array without Marshaling it? I'm
> > pretty sure the performance hit comes from copying everything during
> > the marshaling process. I know it can be a tricky problem because C
> > chars are 1 byte, and C# are 2.
>
> This is not possible unless you are storing your string in C# as byte[]s.
>
> --
> Chris Howie
> http://www.chrishowie.com
> http://en.wikipedia.org/wiki/User:Crazycomputers
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20081103/dc6d78ae/attachment.html 


More information about the Mono-list mailing list