[Mono-dev] Specifying MarshallAs for [Out] StringBuilder
Kornél Pál
kornelpal at gmail.com
Sun Mar 23 18:10:58 EDT 2008
> I understood that I have to use a StringBuilder with a large enough
> buffer. But what I don't understand is how do I get access to the
> underlying pointer from the StringBuilder ? Are you suggesting that I
> don't rely on Mono's marshalling of stringbuilder<->read-write_string
> but instead write my own marshaller; something like this ?
You cannot obtain that pointer using public methods. But note that that
pointer would be UTF-16 and you need some other encoding so you couldn't use
it directly even if you had it.
> // 3. Read back string and fill in the stringbuilder
> sb.Length = 0;
> sb.Append (do some encoding stuff with PtrToString on the buffer);
You only need to do this if you want to replace the contents of the
StringBuilder. If you just need the string you don't need a StringBuilder,
simply return a string.
Kornél
More information about the Mono-devel-list
mailing list