CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2005
    Posts
    221

    Class' Methods included in application?

    If you include and reference a class from within a C++ program but do not actually make use of all of its methods, do those non-referenced methods still get included in the executable?

  2. #2
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: Class' Methods included in application?

    Quote Originally Posted by RogerGarett
    If you include and reference a class from within a C++ program but do not actually make use of all of its methods, do those non-referenced methods still get included in the executable?
    Well, yes and no.
    (Strange answer, ehh? )

    A lot of factors can potentially go into the decisions a compiler makes to not include methods defined in a class. For one - access modifiers. For another - project's settings (choice of optimization used, et al).

    I can imagine compilers ignoring private member methods that are never used.

    As for public ones, I dare say - most compiler will not optimize away methods defined in a class that are declared as (pure-)virtual in an (Abstract) Base Class - one that this class inherits from, even if they are never used.

    BUT, it could still be that the compiler / linker subjects the output to a series of optimizations (one that is influenced by the project's settings too) i.e. to an assembly level optimization which would influence the final deliverable a lot. This optimization may leave for no scope in making 1-to-1 correspondence between the release mode assembly and the C++ code.

    One thing for sure - junk code that is not used will at best increase compilation time, and at worst influence the size of the final binary too. Therefore, it may actually be prudent to evaluate the quantum of time and effort wasted in writing methods that are never used, and also in taking measures that keep this from happening again.
    Last edited by Siddhartha; September 5th, 2006 at 07:23 PM.

  3. #3
    Join Date
    Apr 2005
    Posts
    221

    Re: Class' Methods included in application?

    Siddhartha,

    Thank you for the reply.

    In my case I have several applications which make use of the class, one which makes extensive use of it and others that only need a minimal part of it. So I was hoping that the compiler would be real nice and say, "Hey, he never calls these sixty three methods, I'll just leave them out."

    But some tesing would seem to indicate that it doesn't do that. My one application that uses very little of the class went from 424K to 503K when I added that class.

    I'll have a look around at optimization settings and see if I can come up with something. Or try splitting the class up some how.

    - Roger

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured