Groups | Blog | Home
all groups > dotnet clr > august 2005 >

dotnet clr : MSIL Sizes and CS->EXE->IL


David Betz
8/24/2005 12:28:03 PM
Dear MVPs:

I have an interesting question for you...well, I find it interesting at
least. I am giving a talk on .NET technologies next Friday and while I was
working on creating a few examples I noticed something in my work that I had
not noticed before.

When I compile a simple C# hello world application as follows, I get a 3,072
byte executeable

public class HelloWorld {
public static void Main( ) {
System.Console.WriteLine("Hello World!");
}
}

....but when I "ildasm /out=helloworld_cs_il.li" that and then "ilasm
helloworld_cs_il.il" THAT I get a 2,048 byte file.

Even when I do this with VB, my exe goes from 6,144 bytes to 5,140 bytes.

Of course a direct IL implementation of a simple Hello World example (which
wouldn't require a class at all; well, it's identical to your Hello World
example), renders something as 2,048 bytes, which is the same size as what
the C# version went to after a visit from ildasm and ilasm. Since it's 2^11,
I can only assume that's some sort of minimum because I would think that the
IL version would be smaller than the CS->EXE->IL->EXE version.

So,

Question 1: Why in the world would my C# code which went to EXE(3,072) back
to IL and then to EXE again get SMALLER when I disassembled and reassembled?
Or why the VB version shrunk?

Question 2: Is my theory about 2,048 bytes as a minimum even close?

Question 3: It's not a big deal, but do you think it's a coincidence that
the VB version is EXACTLY twice the size of the original C# version?

David Betz
8/24/2005 3:18:01 PM
Thanks for the help, that explains a lot. As far as Q3... I'm not talking
about explorer, this is all in a command prompt. In Explorer actually, the
sizes of all of them ON DISK is 4k. So it still seems to be a weird thing
that

1) the IL is 2*(1024)
2) the C# is 3*(1024) and
3) the VB is 6*(1024)

Any other ideas on this one?

Also, I did verify your number of 1,536 bytes with

..assembly small {}
..method public static void asdf( ){ .entrypoint }

I'm form the old DOS days and when you would change something, the size
would show up so it's weird to me why, for example, the above is the same
size as the following which has a longer method name. There's gotta be some
sort of 'minimum chunk size' concept with CLR executables or something...this
is my theory with Q3 as well. I donno... any ideas?

..assembly small {}
..method public static void asdfasdfasdfasdfsd( ){ .entrypoint }

[quoted text, click to view]
Mattias Sjögren
8/24/2005 10:55:51 PM
[quoted text, click to view]

The C# and VB compilers include a version resource (the old-style
Win32 resource format, not a managed resource). It doesn't
automatically get included in the reassembled executable, you have to
include it with the /resource switch. This could explain the smaller
executable size.


[quoted text, click to view]

Minimum for what exactly? The most trivial assembly I can create gives
a 1536 byte executable when compiled with the v1.1 Ilasm.exe. The IL
assembler code is simply

..assembly x {}


[quoted text, click to view]

Yes, and it even sounds a bit too good to be true that they both are
multiples of 1K. How are you checking the file size? If you do it in
Explorer, you're not looking at the Size On Disk number are you?



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button