[Mono-list] Marshal.SizeOf() vs. sizeof operator

Giuseppe Greco gius.greco@bluewin.ch
Tue, 12 Aug 2003 14:29:05 +0200


Hi all,

Marshal.SizeOf() and the sizeof() operator
return the same result, so what's the real
difference between them?

Until now, I've used Marshal.SizeOf()...
and with Mono on Linux it works fine.

This morning I've had the good (or bad) idea
to test my code on Windows with .NET... and
the result was

1. Marshal.SizeOf() is unable to determine the 
   type of custom classes

2. for char types, Marshal.SizeOf() always returns
   "System.byte[]" instead of "System.Char"

A workaround could be to replace Marshal.SizeOf()
with the sizeof() operator... already tried: it
works.

At the end of the story, regardless whether or not
it works on Windows, when should one use
Marshal.SizeOf() instead of the sizeof() operator?

Thanks,
Gius_.