Thread: Filesize

    #1
  1. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12

    Filesize


    Compiler is Microsoft Visual C++ .NET, architect edition
    I want the smallest filesize possible with C, without packing/compressing. This program that doesn't do anything is 20.5K, If I just have an int main() without any includes, it's around the same size, if not bigger.. why?
    Does the size differ greatly with each compiler? What causes the huge filesize for `programs that don't do anything`.
    I compile with default settings, "release", not "debug"..

    I opened some files in notepad, and found this, what is it?

    --
    TLOSS error
    SING error
    DOMAIN error
    R6028
    - unable to initialize heap
    R6027
    - not enough space for lowio initialization
    R6026
    - not enough space for stdio initialization
    R6025
    - pure virtual function call
    R6024
    - not enough space for _onexit/atexit table
    R6019
    - unable to open console device
    R6018
    - unexpected heap error
    R6017
    - unexpected multithread lock error
    R6016
    - not enough space for thread data

    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.
    R6009
    - not enough space for environment
    R6008
    - not enough space for arguments
    R6002
    - floating point not loaded
    Microsoft Visual C++ Runtime Library

    Runtime Error!

    Program: ... <program name unknown>
    --

    Code..
    Code:
    #define WIN32_LEAN_AND_MEAN 
    #include <windows.h> 
    
    int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR CmdLine, int CmdShow)
    {
    	
    	return 0; 
    }
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    if you use linux you can use the strip utility to make your programs much smaller. it removes the symbol table and all sorts of other stuff that i dont know about. there's always lots of junk inside of your exe's. also i think it depends how you link, statically or dynamically. the former making a much larger exe. all this stuff can be found with 'man gcc' but i'm not sure about in windows sorry.

    edit: here's a small example of the crap packed into you exe, this is for a program like so:
    Code:
    #include <stdio.h>
    
    main(){printf("blabla\n");}
    <:root:> gcc test.c
    <:root:> gcc test.c -s -o b.out
    <:root:> ls -al
    total 36
    21:29 ..
    -rwxr-xr-x 1 root root 11353 Aug 26 15:47 a.out
    -rwxr-xr-x 1 root root 2680 Aug 26 15:47 b.out
    pretty big difference.
    Last edited by infamous41md; August 26th, 2003 at 02:40 PM.
  4. #3
  5. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    Welcome to the wonderful world of Windows bloatware. I have had 50 line codes wind up with exes of more than a couple of megabytes! You can try asking to minimize the size of your code under optimzations (Project, Settings, C/C++, Category "Optimizations") and see if that makes any difference (didn't for a program I tested it on). I imagine, as infamous41md pointed out, that there are possibly ways to strip some of that out of your exe, but some of that stuff is needed for the runtime linker (for DLLs) and if you try to remove it it is nearly 100% likely your program will crash.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  6. #4
  7. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12
    Damn, yes, none of the settings in msvc do ANYTHING, not even a byte off.


    I compiled with mingW, 14K, not bad.
    Last edited by movEAX_444; August 26th, 2003 at 03:19 PM.
  8. #5
  9. ASP.Net MVP
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Aug 2003
    Location
    WI
    Posts
    4,378
    Rep Power
    1510
    You're building a win32 application. Try building a console application with this code and see if that helps the file size:

    void main(){}
    Primary Forum: .Net Development
    Holy cow, I'm now an ASP.Net MVP!

    [Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

    http://twitter.com/jcoehoorn
  10. #6
  11. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Also, some of the obvious things are to check whether you are building a debug or release version of your program and whether you are statically or dynamically linking in the libraries.

    Those made a difference in MSVC++6, but I don't know yet whether they would in .NET. I'm just starting my VB.NET class tonight [shudder].
  12. #7
  13. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12
    Yeah, I am 'releasing', debug is like 108K at least. I don't use anything .NET, I just use msvc because of the IDE, I will probably compile w/ mingW when I'm done tweaking the projects around.

IMN logo majestic logo threadwatch logo seochat tools logo