What Gets Compiled From a Linked File?

  • Thread starter Thread starter Jeff Gaines
  • Start date Start date
J

Jeff Gaines

When I run a build from the IDE in VS2008 does the output file include all
the functions in a linked file or just those used by the program?

i.e. if I have a library file with 100 functions in it but only 10 are
used by the program do they all get included or just the 10 that are
actually used?
 
When I run a build from the IDE in VS2008 does the output file include
all the functions in a linked file or just those used by the program?

i.e. if I have a library file with 100 functions in it but only 10 are
used by the program do they all get included or just the 10 that are
actually used?

If you mean a .NET DLL with classes and methods, then nothing
get included. It just uses the definitions for compilation and
the DLL will still be needed at runtime.

Arne
 
If you mean a .NET DLL with classes and methods, then nothing
get included. It just uses the definitions for compilation and
the DLL will still be needed at runtime.

Arne

Hi Arne

I tend to add a reference to the library source file directly rather than
a dll, on the basis I'm bound to want to add/change something.
I just wondered if the whole file gets compiled or just the functions in
it that are actually referenced.
 
Jeff said:
I tend to add a reference to the library source file directly rather
than a dll, on the basis I'm bound to want to add/change something.
I just wondered if the whole file gets compiled or just the functions in
it that are actually referenced.

It's easy enough to check. You can get ILSpy from http://www.ilspy.net/
- then use it to open your DLL and see whether any unused code is present.
 
I tend to add a reference to the library source file directly rather
than a dll, on the basis I'm bound to want to add/change something.

I don't like that approach, but ...
I just wondered if the whole file gets compiled or just the functions in
it that are actually referenced.

All public code must be in the output as someone may want to call it
later.

I would even expect the non public stuff to be there as one can do some
ugly things via reflection.

But it should not matter much, because IL is a rather compact format
so the extra space must be minimal.

And the unused code will not be JIT'ed.

Arne
 
I don't like that approach, but ...

This is hobbyist stuff though, I would never fit in a professional
programming environment!

All public code must be in the output as someone may want to call it
later.

I would even expect the non public stuff to be there as one can do some
ugly things via reflection.

But it should not matter much, because IL is a rather compact format
so the extra space must be minimal.

And the unused code will not be JIT'ed.

OK, thanks :-)

The test program and whole library is only 51 KB, I can live with that.
 
You can get the same information from the ILDASM.EXE tool that comes with
Visual Studio.

That said, I know for sure that you will find that an assembly compiled
from C# code by the Visual Studio compiler will contain all of the members
in the original C# code.

Thanks Peter :-)

I've been trying to decide whether to use one central library or use a
separate one for each program. There are pros and cons of course, I'm just
trying to avoid duplication and re-inventing the wheel/
 
This is hobbyist stuff though, I would never fit in a professional
programming environment!

You should still consider doing it the right way.
OK, thanks :-)

The test program and whole library is only 51 KB, I can live with that.

Yes.

I am pretty sure that you will get bigger hard disks a lot faster than
you can write code to build DLL's from.

Arne
 
Looks interesting but seems to require NET 4 which I don't have.

There are other tools. .NET Framework ILDASM, dotPeek etc..

BTW, unless you are on a very old Windows then you can install .NET 4
(it can coexist with 2.0 and 2.0/3.5).

Arne
 
I've been trying to decide whether to use one central library or use a
separate one for each program. There are pros and cons of course, I'm
just trying to avoid duplication and re-inventing the wheel

Go for central library.

Arne
 
Back
Top