地圖我有箱的數組:的std ::使用大量的內存
vector<vector<int> > bins
程序計算大量的類型Term
和對應的整數的對象。每個bin都與一個對象Term
相對應,並且ints需要以bin結尾。我目前做這個:
map<Term, int> helperMap;
int binNumber=0;
while(/*some condition*/)
{
Term temp;
int tempInt;
//Do some calculation to find temp & tempInt
if (helperMap.find(temp)==helperMap.end())
{
vector<int> newBin;
newBin.push_back(tempInt);
bins.push_back(newBin);
helperMap[temp] = binNumber;
binNumber++;
}
else
{
bins[helperMap.find(temp)->second].push_back(tempInt);
}
}
的問題是,在地圖(我不再需要進一步的)需要比箱式結構更多的內存,而這將嚴重製約上的程序。有沒有更有效的方法來做到這一點?
這聽起來像是一個XY問題:http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – 101010
以什麼方式?我確定'Term'對象的計算是必需的。 – RobVerheyen
我們是否應該假設'Term'和'Object'在這段代碼中是同義的? – WhozCraig