2017-08-11 82 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