PDA

View Full Version : devc++ vs msvc++ - size



Unregistered
02-27-2002, 09:58 AM
ok i know this has been covered before but i can't find it anywhere. when i enter this code:

#include <windows.h>

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
MessageBox(0, "World", "Hello",0);

return 0;
}
into DevC++ the exe is 4kb but when i enter the same code into MSVC++ the exe is 24kb. why does msvc++ change the size so much? thanks.

Govtcheez
02-27-2002, 10:01 AM
There's probably some compiler option to make the exe smaller, althoguh I can't think where that would be right now...

Fordy
02-27-2002, 10:35 AM
Few reasons...

Is MSVC set to release instead of debug?

Has either compiler been set to optimise for size?

Also the implementation of the libraries will be different between compilers...

And I wouldnt trust such a small program as an indication of which compiler creates the smallest.

nvoigt
02-27-2002, 12:54 PM
Size matters not. Judge me by my size, do you? </yodavoice>

Brian
02-27-2002, 02:27 PM
Originally posted by Ken Fitlike
UK has recently recognised Jedi Knight as a religion

Not true, they have just added the religion "Jedi" to the census computers so it is recognised and does not produce a question. because of the amount of time they have to waste with all the false Jedi entries. It is still not an official religion.

Brian
02-27-2002, 05:19 PM
Originally posted by Unregistered

into DevC++ the exe is 4kb but when i enter the same code into MSVC++ the exe is 24kb. why does msvc++ change the size so much? thanks.

Well, this code in MASM32



; ######################################

.486
.model flat, stdcall
option casemap :none ; case sensitive

; ######################################

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib

main PROTO

; ---------------------
; literal string MACRO
; ---------------------
literal MACRO quoted_text:VARARG
LOCAL local_text
.data
local_text db quoted_text,0
.code
EXITM <local_text>
ENDM
; --------------------------------
; string address in INVOKE format
; --------------------------------
SADD MACRO quoted_text:VARARG
EXITM <ADDR literal(quoted_text)>
ENDM

; ##########################

.code

start:

call main

invoke ExitProcess,0

; #############################

main proc

invoke MessageBox,0,SADD("World"),SADD("Hello"),MB_OK

ret

main endp

; ###############################

end start


Makes an exe only 2.50KB. Yeah ASM wins! woo.

Brian
02-27-2002, 05:22 PM
Originally posted by Ken Fitlike


None of them are.



No, others are official religions. If you put Jedi on your job application you would probably be told to **** off.

ggs
02-27-2002, 06:11 PM
there's been a 512 byte windows demo using opengl :P
anybody seen stoerfaller ost?

small code rocks :)

Fordy
02-28-2002, 03:34 AM
I'm a Jedi too -> click here (http://www.cprogramming.com/cboard/showthread.php?s=&threadid=2832&highlight=jedi)

On the note on executable size......so what!!
ASM produces an executable thats 500 bytes smaller than a fully optimised executable.........big deal........The application, reusability and structure of a programming language is far more important than such a size difference.....

DarkStar
03-01-2002, 05:12 PM
Size matters not.

I beg to disagree...

When building an exe, you should always strive for balance between size and speed. The smaller the exe file is without loss of executable speed, the better. There should be no question to this logic whatsoever.

DarkStar
03-01-2002, 05:25 PM
On the note on executable size......so what!!
ASM produces an executable thats 500 bytes smaller than a fully optimised executable.........big deal........The application, reusability and structure of a programming language is far more important than such a size difference.....

Where are you coming from...

I've seen some really stupid and bulky software written in HLL. Take for example the shareware "One Step Shutdown". This software is supposed to give the user the ability to quickly shut down their computer. This software is 2.9 Mb in size. I know of an ASM program only 1 Kb in size that does exactly the same thing, faster and safer. And it's FREE !

Sorensen
03-01-2002, 05:30 PM
>I beg to disagree...

Well if you've only got an sizeof(operating system) + 2.50 Kb hard drive then I agree. But as hard drive space is cheap, developers don't have to spend time doing unnecessary optimisations (such as the c to asm conversion in this thread). Which means software is available earlier, and at cheaper cost.

The only reason to be obsessive about size is when performance is critical (in which case only the parts of your program that need to run fast will benefit from being small), or if your programming in an environment that requires it.

DarkStar
03-01-2002, 05:43 PM
The only reason to be obsessive about size is when performance is critical


Writing computer programs with the smallest and fastest possible code, should be the absolute goal of every good programmer, no matter what language he or she may use.

Fordy
03-01-2002, 05:45 PM
Originally posted by DarkStar
Where are you coming from...

I've seen some really stupid and bulky software written in HLL. Take for example the shareware "One Step Shutdown". This software is supposed to give the user the ability to quickly shut down their computer. This software is 2.9 Mb in size. I know of an ASM program only 1 Kb in size that does exactly the same thing, faster and safer. And it's FREE !

As far as I can see the example you provided shows little or no comparison to the case in point....

Agreed.....some freeware piece of junk that takes 3MB to shutdown a system is excessive and rather wastefull, but a size loss of 500 bytes to build the executable listed at the head of this thread in C/C++ is probably worth it when you compare it to the extra work gone into the ASM example that Brian has also provided earlier....

Sorensen
03-01-2002, 05:52 PM
>Writing computer programs with the smallest and fastest possible code, should be the absolute goal of every good programmer, no matter what language he or she may use.

Why? I'm not saying that it's not better to produce smaller code if there are no other major costs/effort involved. But if you're paying more for your software as a result there's little sense in going to extremes (unless you're living in a world where programmers get as much time as they require and all software is free).

DarkStar
03-01-2002, 06:06 PM
I have one question to ask, how did you guys get all of that text in between your quote tags ?! I can't do it for the life of me !

Fordy
03-01-2002, 06:14 PM
Originally posted by DarkStar
I have one question to ask, how did you guys get all of that text in between your quote tags ?! I can't do it for the life of me !

The easiest way is use the quote button below this text and to the right

Sorensen
03-01-2002, 06:15 PM
the quote.

Nick
03-01-2002, 06:20 PM
This is due to msvc++ linking one of the libraries statically that dev-c++ linked dynamically.