What is a good CPU/PC setup to speed up intensive C++/templates compilation?

I currently have a machine with an Opteron 275 (2.2Ghz), which is a dual core CPU, and 4GB of RAM, along with a very fast hard drive. I find that when compiling even somewhat simple projects that use C++ templates (think boost, etc.), my compile times can take quite a while (minutes for small things, much longer for bigger projects). Unfortunately only one of the cores is pegged at 100%, so I know it's not the I/O, and it would seem that there is no way to take advantage of the other core for C++ compilation?


Compile time problems with templates are often link problems, rather than compilation problems.

Using templates internally in your .cpp files, but making sure that the headers don't actually include the template, is a good way to fix those. That can be done by either forward declaring the class, or wrapping your implementation class in an abstract base class that just declares the public members (the Pimpl Idiom, basically).


Are you using pre-compiled headers? They typically provide the biggest compilation speed boost I get with my C++ projects.

Also, depending on your compiler, you can enable multi-thread compiling. For example, with Visual C++, it's the /MP switch (see here for details), though enabling /MP isn't always possible, depending on what other command-line options you use.


为了利用基于Makefile的系统进行多线程编译,请查看-j开关,通常的建议是调用

make -j<number of cores + 1>
链接地址: http://www.djcxy.com/p/14984.html

上一篇: Objective中的非规格化浮点

下一篇: 什么是一个好的CPU / PC设置来加速密集的C ++ /模板编译?