I recently added a static search array to one of my classes, for example:
class MyClass
{
static MyClass const s_fromIndex[1500];
public:
MyClass(size_t arg1, size_t arg2);
static MyClass fromIndex(size_t index) { return s_fromIndex[index]; }
}
MyClass const MyClass::s_fromIndex[1500] =
{
MyClass(0, 1), MyClass(0, 2), MyClass(0, 3), MyClass(0, 4),
...
};
The reason for the array is that calculating the index by two parameters is quite expensive (despite the appearance of it in the code example). Since the index is limited to 1500, I decided that I would return the objects from the lookup array.
The class is in the static library project. I soon noticed that whenever I used MyClass in my executable project, the step “generating code” during construction suddenly went in for a very long time (2-3 minutes). Previously, this step was carried out almost instantly. Assembly debugging is still very fast.
When I take out a static array, everything builds smoothly again.
, , .
, ? / ?
: , . , . , , MyClass , , . , ( ) . - . , - .