2016-12-04 55 views
1

這被編譯在64位VS C++ 2015的std ::發生bad_alloc的,其中x是特別1120.push_back()上的大載體引起的std :: bad_alloc的

static std::vector<std::vector<std::vector<double>>> g_damagefunction; 
static std::vector<std::vector<double>> g_has_damagefunction; 
static std::vector<double> null_v_double; 
static std::vector<bool> null_v_bool; 
static std::vector<std::vector<double>> null_vv_double; 
int main(){ 
for (int x = 0; x < 4400; x++) { 
    std::cout << x << '\n'; 
    g_damagefunction.push_back(null_vv_double); 
    g_has_damagefunction.push_back(null_v_bool); 

    for (int y = 0; y < 2000; y++) { 
     g_damagefunction[x].push_back(null_v_double); 
     g_has_damagefunction[x].push_back(false); 
     for (int i = 0; i < 41; i++) { 
      g_damagefunction[x][y].push_back(0.0); 
     } 
    } 
} 
} 
+0

我認爲它使用了太多的內存。你應該能夠看到到達崩潰點時使用了多少內存。 –

+1

[無法複製](http://coliru.stacked-crooked.com/a/fafd1d273a5f4e1f) –

+0

@πάνταῥεῖ它在1040結束。當我在coliru上嘗試時,我已經過期。 –

回答

0

bad_alloc的在這裏意味着您正在運行出的記憶。 g_damage函數向量中的double元素的大小將取(4400 x 2000 x 41 x sizeof(double))個字節,相當於您的內存大約2.68 GB。如果向它添加矢量本身佔用的內存量,則可以清楚地看到,計算機的RAM不足以滿足程序的要求,或者程序使用的內存太多。我懷疑後者是如此。