Advertisement

Missile Command code review request

Started by August 22, 2014 01:46 PM
14 comments, last by BHXSpecter 10 years, 5 months ago

As the number of classes grows, your compile time will get worse and worse. Ideally, when you update a header, only source files that depend (directly or indirectly) on that header should need to be recompiled. When you have a single header that includes all of the classes, any change is going to cause all the files to be rebuilt.


I'm using Visual Studio, as far as I can tell it only compiles the files that have been edited, and if I'm not mistaken, I believe that it doesn't compile files just because they were included by another. Or, I could be totally wrong about that...


For example, using an array.
for(int n=0; n<6; ++n) {
static float const data[] = {100, 200, 300, 600, 700, 800};
_bases[n] = EntityC(50, 10, sf::Vector2f(data[n], 520), _baseColor);
}
Maybe not worth it for such a small piece of repetitive code, but at least it begins to separates the data from the code.


I never really considered the possibility of simply creating a data array to fill another array. Wouldn't it be expensive though to recreate the array every iteration of the loop?


For example, using an array.
for(int n=0; n<6; ++n) {
static float const data[] = {100, 200, 300, 600, 700, 800};
_bases[n] = EntityC(50, 10, sf::Vector2f(data[n], 520), _baseColor);
}
Maybe not worth it for such a small piece of repetitive code, but at least it begins to separates the data from the code.


I never really considered the possibility of simply creating a data array to fill another array. Wouldn't it be expensive though to recreate the array every iteration of the loop?

The array is constant and has static duration. Your compiler will allocate it at compile time and there's zero additional cost at run-time other than actually accessing it from memory.

Advertisement


I'm using Visual Studio, as far as I can tell it only compiles the files that have been edited, and if I'm not mistaken, I believe that it doesn't compile files just because they were included by another. Or, I could be totally wrong about that...

You can think of #include as basically copying the included file into the current file.

If "A.cpp" has #include "B.h", and something inside "B.h" changes, "A.cpp" will need to recompile.

Hello to all my stalkers.

The array is constant and has static duration. Your compiler will allocate it at compile time and there's zero additional cost at run-time other than actually accessing it from memory.


Oh, I missed the static part. Thanks for clarification.

You can think of #include as basically copying the included file into the current file.

If "A.cpp" has #include "B.h", and something inside "B.h" changes, "A.cpp" will need to recompile.


I figured that, but I thought Visual Studio somehow did it differently. Suppose not.


I figured that, but I thought Visual Studio somehow did it differently. Suppose not.

You were right, from what I remember of VS and most other robust IDEs. If you edit, like Lactose! pointed out, a header file, then usually the IDE will recompile all files that include it, but there are some IDEs that will recompile everything. That said, it usually is a better idea to do a fresh rebuild of all files every once in awhile, just to be on the safe side.

This topic is closed to new replies.

Advertisement