dimanche 7 août 2016

best method for improving compilattion speed in c++

I have a C++ project which has more than 50 classes. These classes can be categorized into 7 different folders but most of these classes are used in different parts of the code. As I use Netbeans for development, It compiles and link all object files to each other. Consequently it links all files to others which take lots of time. For removing this problem, I used CMake and tried to separately compile each category independently to dependent each category to all required ones. But after some time lots of "Undefined reference to ..." begins when I includes some headers in other modules. The new solution which is proposed to me is creating a Facade class for each category which handles each category operation. But in order to remove include dependency, it was said that I can not use public functions of each categories classes. instead I have to get target object and give it to a function of Facade class to execute it for me in other classes. for example suppose this scenario:

Class A{
    int calculateSomething(string str);
}

Class AFacade{
    static int calculateSomething(Class A*, string str){
        return A->calculateSomething(str);
    }

    static A* getA(){
        return new A();
    }
}

Class B{
    void someMethod(){
         A* aptr = AFacade::getA();
         int tmp = AFacade::calculateSomething(aptr,"test");
    }
}

Although this solution seems to resolve my issue but it is weird. because it actually is preventing function calls and is giving this permission to some specific class (7 categories Facade classes). Do you think that this solution is correct? can you offer any better solution for solving this problem?

Aucun commentaire:

Enregistrer un commentaire