how to decreasing binary size?

This is a discussion on how to decreasing binary size? within the C Programming forums, part of the General Programming Boards category; Hi, how are libraries linked and how it effects the binary size? ex: I am using printf() in my application, ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    139

    how to decreasing binary size?

    Hi,

    how are libraries linked and how it effects the binary size?

    ex: I am using printf() in my application, which intern uses standard library.
    Now will the entire library appear in my binary or only the printf() piece of code.

    It would be wonderfull if someone can show me a good doc on following process.

    Thanks to all

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    printf will drag in quite a bit of the standard library, but certainly far from ALL of it.

    Depending on the OS architecture, the standard library may even be a shared libryar/DLL.

    What are you trying to do? Is this for an embedded project?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    139
    Thanks for your time.......Yes indeed ...

    I am Planning to prepare a library set , with certain exposed API's.
    Now coming to the problem my chip has a memory limitation say about 128KB....
    Struck how to go about.....

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, the way the a library works is that each object file is seen as a separate unit. This also means that you want to make each source file as small and as separate as possible (that is, try not to make the source call too many other functions).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    139
    Thanks....

    Is their any example or can you point me to an helpful document that show me things practically.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Not really. What I posted was a combination of common sense and a many years of experience in working with things, embedded and otherwise.

    You may also want to consider that for space optimization, reusing one function many times is better than using multiple functions. So if you can do some similar thing in different ways, you may want to use the SAME method everywhere.

    As an example: You need to build a string from several other strings in one place, and produce a string from a string and some number in another place. The obvious solution for the first case is a sequence of strcpy()/strcat(), whilst the second can be done with either sprintf() or strcpy()/strcat()/itoa().

    If you choose to use strXXX functions in the first case, then re-using strcpy() rather than using sprintf() in the second case, will avoid adding sprintf() to the components your system needs to drag in. This ONLY works if you can completely avoid using sprintf, of course. On the other hand, if you DO have to use sprintf someplace, then you may as well use it for both of the above cases (but it's quite unlikely that you can completely avoid using strcpy()/strcat() in your code - of course, it DOES depend on what your code is doing).

    But as a summary, try to avoid using three different ways of doing similar things - use one, consistently.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Obviously, another part would be to set the compiler to optimize for size - most compilers will have the options to compile for size or for speed.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generic heapsort
    By Sephiroth1109 in forum C Programming
    Replies: 15
    Last Post: 12-07-2007, 05:14 PM
  2. arrays vs lists? And containers in general!
    By clegs in forum C++ Programming
    Replies: 22
    Last Post: 12-03-2007, 01:02 PM
  3. char problem
    By eXistenZ in forum Windows Programming
    Replies: 36
    Last Post: 02-21-2005, 05:32 AM
  4. Replies: 11
    Last Post: 03-25-2003, 04:13 PM
  5. binary
    By webturtle0 in forum A Brief History of Cprogramming.com
    Replies: 52
    Last Post: 12-05-2002, 01:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21