Tuesday, February 12, 2013

Reducing build time on VisualStudio

I was working on a project recently where there was a statically allocated array (a lookup table of sorts) that was used in the code. I declared the array as follows:
float lookupTable[512][512]={{0.3423f,0.23453f, .... }
                                                  ...};
To my surprise, visual studio build process stuck as soon as the source file containing this table was build. I went online to see how to solve this issue and luckily I found this (http://forums.codeguru.com/showthread.php?515152-Build-with-extrememly-large-array-constant-hangs-at-quot-Generating-code-quot ) thread which mentioned to declare the array static at global /class scope and making it a const. I just did that by declaring my lut as follows:
static const float lookupTable[512][512]={{0.3423f,0.23453f, .... }
                                                  ...};
and voila, the build time reduced to virtually milliseconds.
Thought it might help others as well.

2 comments:

LiLin said...

"Those tables should be defined at global scope (or static class scope).
They should be const
not doing both will usually cause the compiler to create an empty table, with code to fill the table. You'll end up with a biggger exe, that also takes extra time to start up."

did not know that, thanks for sharing !

MMMovania said...

You are welcome :)

Popular Posts

Copyright (C) 2011 - Movania Muhammad Mobeen. Awesome Inc. theme. Powered by Blogger.