起初,我在應用程序啓動時將所有變量加載到內存中。隨着時間的推移,變量的數量變得如此之大,我不想再這樣做了。 相反,我只在需要時才檢索它們(使用映射文件,但那是另一回事)。文件中的數據位置
起初我寫的變量到一個文件中。 (這是重複多次的...)
vector<udtAudioInfo>::iterator it = nAudioInfos.Content().begin();
for (;it != nAudioInfos.Content().end(); ++it)
//I think here I should store the position where the data will begin in the file
//I still need to add code for that...
//now write the variables
fwrite(&it->UnitID,sizeof(int),1,outfile);
fwrite(&it->FloatVal,sizeof(double),1,outfile);
//I think here I should store the length of the data written
//I still need to add code for that...
}
但現在,我需要動態地加載變量,我需要跟蹤的其實都是存儲在哪裏。
我的問題是:我怎麼能找出當前寫入位置?我認爲並希望我可以使用它來跟蹤數據實際駐留在文件中的位置。
你有沒有看着'ftell'? – GWW 2013-05-04 19:45:20