Assembly size C# ./. VB.NET

  • Thread starter Thread starter Jens Thiel
  • Start date Start date
J

Jens Thiel

When I compare a C# and nearly identical VB.NET project, the C# generated
assembly has almost twice the size of the VB assembly. IL code is nearly
identical, but the C# generated assembly contain lots of 00 00 00. What's
that? Or better: How can I stop that?

Jens.
 
Jens,
When I compare a C# and nearly identical VB.NET project, the C# generated
assembly has almost twice the size of the VB assembly. IL code is nearly
identical, but the C# generated assembly contain lots of 00 00 00. What's
that? Or better: How can I stop that?

Which compiler options are you using? Are you looking at release or
debug builds? Strong named or not? Do the assemblies contain any
resources?



Mattias
 
Mattias Sjögren said:
Which compiler options are you using? Are you looking at release or
debug builds? Strong named or not? Do the assemblies contain any
resources?

VS.NET 2003, FrameworkVersion=v1.1.4322
C# class library, default settings, Release build: 16,0 KB (16.384 bytes)
VB.NET class library, default settings, Release build: 5,00 KB (5.120 bytes)

I'm no VB programmer, but the default settings should be similar. No res or
sn.
Oh wait, manifest says .file alignment 512 != 4096.

Bingo, found it. Setting 512 in CS yields: 3,50 KB (3.584 bytes)

Does that have any performance impact?

Jens.
 
Hi Jens,

Thanks for posting in this group.
Yes, it seems that the default File Alignment settting of C# project is
4096 while VB.net project is 512.
This File Alignment setting will lets you specify the size of sections in
your output file.
The small File Alignment setting will result small file size, because there
will be less padding between the sections.

The article below talks about the technicals you can use to reduce
executable size. But it only talks about VC++, maybe it also helps you, for
your informtion:
http://www.catch22.org.uk/tuts/minexe.asp

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
"Jeffrey Tan[MSFT]" said:
Yes, it seems that the default File Alignment settting of C# project is
4096 while VB.net project is 512.
This File Alignment setting will lets you specify the size of sections in
your output file.
The small File Alignment setting will result small file size, because there
will be less padding between the sections.

The article below talks about the technicals you can use to reduce
executable size. But it only talks about VC++, maybe it also helps you, for
your informtion:
http://www.catch22.org.uk/tuts/minexe.asp

Jeffrey,

thanks for the link. It is a good summary of native VC++ techniques to
reduce code size. What I really like to know is:

a) Are there any negative effects (on performance, compatibility, startup
time, working set size, ...) when I change the default setting to 512?

b) Why is the default File Alignment settting of C# projects 4096 while for
VB.net project it is 512? Both compiler produce nearly identical IL code!


Jens.
 
Hi Jens,

Thanks for your feedback.
Actually, the system can use the file alignment value between 512 and 4096,
which have no different performance issue.
So you can reduce the file size through change project's file alignment
setting without performance impact.

For the different choosing of file alignment setting in C# and VB.net, I
think it is by design, it is just .Net development team chooses different
default values.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top