Friday, July 31, 2009

Programming Efficiency?

So I compiled a hello world in Dev-C++.


500k





I compile it in C


15k





Then I see....





Command Line wave player


http://www.cmdtools.com 2k





I look at one of those crazy hacker groups crack files


30k


- Has amazing music, definitely NOT MIDI


- Preforms a complex function assumedly


- Has transparency


- Is graphically Cool/colorful











What gives? I've researched assembler, but even then, I'd have to send it as an object in C code, further bloating it. Making a self executable in assembler sounds impossible although someone made their own highly featured OS with only 600k http://en.wikipedia.org/wiki/MenuetOS .

Programming Efficiency?
Actually, there are two different things to consider: The first is efficiency in speed, the other is efficiency in size.





First and foremost: you will always hear the saying "premature optimization is the root of all evil", which was quoted by Donald Knuth, math professor and author of the "Art of Computer Programming" series. In some cases, I do not agree with this statment, especially when the person who is making the supposed 'premature' optimization is making an educated optimization by knowing the architecture and knowing the end result.





That being said, there are two things (or a combination of the two) that are bloating your code. The first is that you are building a "debug" version of your code, which has unoptimized assembly and additional information used while debugging the application at run-time.





The other option is that you are "statically" linking your application with the run-time library. Static linking will pull in all of the code and dependencies for that code (the run-time are functions that you use, but didn't write yourself) and then it will reside in your executable. "Dynamically" linking, or having a DLL loaded at run-time will result in a much smaller executable, but when your application runs, it will load the DLL into its memory space and still take up memory resources.





Applications written in 'C' using only dynamic link libraries or those written in assembly can be the smallest and most efficient. However, chances are that they still use dynamic link libraries in the operating system. You can use a utility, such as dependency walker, to see what dynamic link libraries an application has loaded at runtime.





I've included a link to the (free) utility below.


No comments:

Post a Comment