Boost logo

Boost Users :

Subject: Re: [Boost-users] Dynamically creating new units
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-12-25 20:38:25


On Fri, Dec 25, 2009 at 6:30 PM, Brandon Olivares
<programmer2188_at_[hidden]> wrote:
> On 2009-12-25, OvermindDL1 wrote:
>> Yep, that is the major hazard of C++.  If you learn how to structure
>> things differently and use forward declarations and less class member
>> functions (use external functions instead, ala C), that can speed up
>> compilation tremendously.

Ah, but you can, depends on how you can abstract your system. Think
of how C works with void pointers and such and you can start to see
patterns for your classes. Think of this.

Say you have a class like this in your header:
class myStuff
{
private:
    someSuperHeavyTemplate<int> mySpecialInt;
    /* other member vars */
public:
    void operateOnMySpecialInt(int i);
    int getSpecialInt(void);
    /* other member functions */
}
And the implementation is in a cpp file, but now everything that uses
this has to include all the nasty and slow instancing for the
someSuperHeavyTemplate<int> type. Now think of this in a C way...
class myStuff;

void operateOnMySpecialInt(myStuff &m, int i);
int getSpecialInt(myStuff &m);
/* other functions that operate on myStuff */

And the implementation contains the implementation of myStuff and the
function definitions. Only that cpp file includes the heavy template
instancing, and all other accesses are fast. You can only do this on
classes/struct that you normally use as pointers in the first place,
but if you can then you can see how you can vastly simplify access to
only what is needed in the public interface, rather then *everything*
that is in the interface.

On Fri, Dec 25, 2009 at 6:30 PM, Brandon Olivares
<programmer2188_at_[hidden]> wrote:
> Well yeah, that's the problem. The units are all typedefs and constants so, AFAIK, you can't use forward declarations.

True, but how much of your code *needs* all of them, only include
those in the cpp by cpp basis, rather then in all headers everywhere.

On Fri, Dec 25, 2009 at 6:30 PM, Brandon Olivares
<programmer2188_at_[hidden]> wrote:
> I'm hoping to perhaps do something similar to the runtime_unit.cpp example. I can declare all of the base units, so to speak, and then hopefully scale them as necessary.
>
> I mostly want to be able to apply any of the SI prefixes to the metric units. Again though if I declare them explicitly, it takes forever to compile.

Still though, upgrade to GCC4.4+ and you will see a dramatic bettering
of compile speed, generally 30% at minimum with heavy template code.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net