В настоящее время я загружаю огромные объемы данных в память, чтобы быстро получить к ним доступ. До сих пор я помещал все в оперативную память. Но теперь, когда мои данные стали слишком большими, я больше не могу этого делать. Поэтому я использую сопоставленный файл.
В этом файле я сохранил векторы «отметок» для аудиофайла.
struct udtPitchmark
{
int ByteStart;
int ByteCount;
};
struct udtAudioInfo
{
int ByteStart;
int ByteCount;
vector<udtPitchmark>Pitchmarks;
};
Я записал огромные векторы «udtAudioInfo» в такой файл:
// Serialize
int iSize = nAudioInfos.Content().size();
fwrite(&iSize,sizeof(int),1,outfile);
vector<udtAudioInfo>::iterator it = nAudioInfos.Content().begin();
for (;it != nAudioInfos.Content().end(); ++it)
{
//we need to know the position that the data will be written to
int iStartPos= ftell( outfile );
fwrite(&it->ByteStart,sizeof(int),1,outfile);
fwrite(&it->ByteCount,sizeof(int),1,outfile);
int len = it->Pitchmarks.size();
fwrite(&len,sizeof(int),1,outfile);
vector<udtPitchmark>::iterator it2 = it->Pitchmarks.begin();
for(;it2 != it->Pitchmarks.end(); ++it2)
{
fwrite(&it2->ByteStart,sizeof(int),1,outfile);
fwrite(&it2->ByteCount,sizeof(int),1,outfile);
}
//and now we need to know the length of the data that was written
int iEndPos= ftell( outfile );
int iLen=(iEndPos-iStartPos);
//now store the file-location info in a map and save this map when we have saved the entire audio info
nMapping.Add (iStartPos,iLen);
}
Вопрос в том, могу ли я легко прочитать один из udtAudioInfos из сопоставленного файла. Я не уверен, можно ли просто скопировать такие структуры из файла в переменную. Спасибо вам за помощь.