[Mono-list] Marshal.SizeOf on Char Type Variations Between Platforms

Robert Jordan robertj at gmx.net
Tue May 11 13:48:41 EDT 2010


On 11.05.2010 17:42, Brian Kesecker wrote:
>
> If the following evaluated (VB code):
>
> System.Runtime.InteropServices.Marshal.SizeOf(GetType(Char))
>
> A test application returns 1 running under Windows (specifically 32-bit 7
> Pro) and 2 running under Linux (specifically openSuSE 11.2 Mono 2.6.4).
> Logically, I would think that 2 should be correct, since Unicode characters
> are two bytes in size.  However, I'm thinking there may be something I'm
> missing, like a default project encoding option, or something to that
> effect.

I believe Marshal.SizeOf(typeof(char)) is returning
one for "orthogonality" with struct marshaling.

When part of a struct, a char will have the *unmanaged*
size of one by default because StructLayout.CharSet defaults
to Ansi for structs. See MSDN docs of Marshal.SizeOf.

Robert



More information about the Mono-list mailing list