2015-10-30 32 views
0

2D和3D陣列向量在整個仿真過程中定義和使用,它們的尺寸非常大,因此需要重新分配資源。從2D混合陣列和向量中釋放內存

array<vector<double>, n> A; 
array<vector<vector<double>, n>, m> B; 

什麼是正確的方法?

+0

你想要的陣列消失或載體的存儲做什麼? – NathanOliver

+0

嗨,他們都是 – jarhead

回答

3

只是讓他們走出去的範圍:

{ 
    array<vector<double>, n> A; 
    array<vector<vector<double>, n>, m> B; 

    // use arrays ... 

} // leave scope, arrays will be deallocated 
+0

你是什麼意思?當模擬完成後,它們被解除分配? – jarhead

+0

@jarhead當它們被定義的範圍被釋放時,它們將被釋放。 –

+2

如果你在變量周圍放置了'{}',它們會在'}'之後被釋放。 http://stackoverflow.com/questions/10080935/when-is-an-object-out-of-scope – ARG