Menu

Help w/ Size Issues

OniLink10
2008-07-19
2012-09-26
  • OniLink10

    OniLink10 - 2008-07-19

    I know that using #include <iostream> includes the ENTIRE iostream Library, but is there any way to make it only include the Functions in it that are used? I know that Visual C++ does that Automatically, but I was hoping there was a Way to do that in Dev-C++. If there isn't a way, can anyone help me with making my Program Smaller? Like Functions to replace the ones I am using with ones not in a Library? The ones I'm using are:
    cout
    cin
    endl
    system("PAUSE")

     
    • OniLink10

      OniLink10 - 2008-07-19

      Oops, I forgot to list that I am using Dev-C++ 4.9.9.2 Portable Edition on a Windows XP Service Pack 3.

       
    • cpns

      cpns - 2008-07-19

      > I know that using #include <iostream> includes the ENTIRE iostream Library,

      No it does not. It includes the ENTIRE header file. MSVC++ does that too - it has no choice.

      > [...] is there any way to make it only include the Functions in it that are used?

      Header files generally contain declarative code only. The linker resolves those declarations to actual code. So long as the library was built from multiple object modules, the linker only actually links those modules from the library needed to actually resolve the references in your code.

      > can anyone help me with making my Program Smaller?

      Linking iostream makes your program larger but the reasons are varied and complex. iostream is just big, and a lot of the code relies on template code, moreover, the issue of size and iostream (or any part of the standard C++ library) is covered at length in several places:

      http://www.mingw.org/MinGWiki/index.php/executables%20large
      http://www14.brinkster.com/aditsu/dev-cpp-faq.html#largeexe

      It is also the case that in VC++ the standard library is provided as a DLL so it does not significantly impact the size of the executable. In MinGW that only applies to the C library.

      > [...]Like Functions to replace the ones I am using with ones not in a Library?

      The easiest way to keep the size down is to restrict your library use to the C library ( <stdio.h> / <cstdio> ). However you would be depriving yourself of a huge amount of functionality and productivity provided by the C++ library. I would suggest that you carefully consider why the size concerns you so much? You should realise that although a simple "hello world" program may increase alarmingly in size compared with a C library version, this overhead is more-or-less constant, and does not grow proportionately with you application size. For any significant project, this overhead is generally negligible. Compared to the size of your computer's memory and hard drive, it is probably already negligible. You may just be sweating the small stuff.

      > system("PAUSE")

      This is part of <stdlib.h> (or <cstdlib>) not iostream. It also does not significantly impact code size, for two reasons a) it does not do much, b) it is provided by MSVCRT.DLL (Microsoft's C runtime library which MinGW uses in place of the GNU C library. It does however use the GNU stdlibc++).

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.