[Mono-devel-list] Re: [patch] support utf8 strings in c# module
Jonathan Pryor
jonpryor at vt.edu
Wed Nov 3 18:14:58 EST 2004
On Wed, 2004-11-03 at 10:07, Joel Reed wrote:
<snip/>
> am i on the right track here? - patch attached. it seems to also fix
> ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len
> we'd want a mono_unicode_from_external like function that took
> a length argument that could be passed to g_convert. any recommendations?
You're on the right track, but it could use some improvements.
First of all, it should follow Mono's coding conventions. This means
tabs, not spaces, and that the '{' should go on the same line as the
'else'.
Second is an issue of efficiency. If you look at the implementation of
mono_unicode_from_external(), it does the equivalent of
mono_utf8_from_external(), followed by a UTF-8 -> UTF-16 conversion
call. After the final conversion of the UTF-16 string into a
MonoString, this means that you have 4 copies of the original string
running around, wasting memory (the original string, the UTF-8 string,
the UTF-16 string, and the final MonoString).
A more efficient implementation would use mono_utf8_from_external(),
then mono_string_new(), resulting in only one intermediate buffer.
- Jon
More information about the Mono-devel-list
mailing list