2017-08-11 46 views
0

这个问题以前已经问过很多次了,但没有一个解决方案似乎对我有用。我创建了我的决策树一个头文件,它看起来像这样编译大的头文件导致编译器在第2遍错误中出现堆空间错误

class PredictClass0 : public CompiledTree 
{ 
public: 
PredictClass0(const std::string& modelDirectory) : 
    CompiledTree(20, 17, modelDirectory) 
    { 
    } 
std::size_t predict_probabilities(const gst::ShottonFeatureAlgorithm &algorithm, const GstFrame* const frame, const std::size_t pixel,const std::vector<ParamValues>& offsetThresholdPair) 
{ 
     if (algorithm.computeFeature(frame,pixel,offsetThresholdPair[0].offsetPairs) < offsetThresholdPair[0].threshold) 
     { 
      if (algorithm.computeFeature(frame,pixel,offsetThresholdPair[1].offsetPairs) < offsetThresholdPair[1].threshold) 
      { 
       if (algorithm.computeFeature(frame,pixel,offsetThresholdPair[2].offsetPairs) < offsetThresholdPair[2].threshold) 
       { 
        if (algorithm.computeFeature(frame,pixel,offsetThresholdPair[3].offsetPairs) < offsetThresholdPair[3].threshold) 

//and the list goes on.... 

头文件的大小30MB的,我有其中3,它需要6个小时编译(最终误差)。我尽可能地尽量减少符号和表达的数量。到目前为止,我已经尝试了这些解决方案:

  • MSDN Solution

  • 设置编译器标志/ MP(多处理器编译)

  • 编译器内存分配M/Z

  • 进行最低限度的构建/ GM

  • 将堆保留和提交大小设置为10000000

在Win 10机器上尝试了所有这些,这些机器上都有32GB RAM和64GB内存。我想知道是否有一个整洁的方式来处理大文件的编译?

+0

你可以预先编译头文件吗? – wallyk

+0

是的,但即使我使用PCH,问题依然存在,需要进行大量的计算。 – MarKS

回答

0

设置堆储备并提交大小〜10000000

你为什么要限制堆到10 MB?尝试将其提高到100 MB甚至500 MB。你有足够的内存可用。

+0

谢谢!好吧,我会试一试。但我想知道为什么Visual Studio不在内部处理这个问题? – MarKS

+0

@马克斯:谁知道?其他编译器呢。但是也许有一个文档缺陷给人的印象是应该提供一个堆大小。如果你没有指定一个,会发生什么? – wallyk

+0

同意!据我所知,在Visual Studio 2013中默认堆大小设置为1MB。但是,当编译器可以使用我的可用内存时,设置自己的堆大小有点肮脏。而且,我没有测试过,我得到了同样的错误。 – MarKS