我一直在PVR後端調度電視錄音,我試圖找出保持一個簡單的數據庫與所有的相關信息。我把一個懶惰的人的原型放在一起(如下所示),但我不想靜態分配巨大的數組,然後將這些對象的RAM內容轉儲到磁盤進行存儲。C++最簡單的數據庫存儲磁盤上的對象的數組或矢量的最佳方式
給出以下懶惰/不良練習原型,我的最佳選擇是什麼?有經驗的程序員如何選擇這樣做?如果我打算全部使用toString/fromString函數,我該怎麼做?
struct Recording{
Date date;
int channel;
int length; //length in hours, minutes, or seconds
bool is_interlaced; //if true, denotes that the episode is interlaced
bool done; //if true, denotes that the episode has been recorded
bool record_successful; //Currently unused
};
struct TV_Episode{
struct Recording recording;
char title[128]; //Episode Title
char season; //Season number
char episode; //Episode number
};
struct TV_Show{
char name[64]; //TV Show name
char numepisodes; //The number of episodes in the array
struct TV_Episode episodes[100]; //Array containing airings of a TV show
};
struct Movie{
struct Recording recording;
char title[128]; //Movie Title, optionally including the year in brackets
};
struct Recordings_DB{ /*
* Obviously these types can be done away with using inheritance
* and the Recordings_DB type can be done away with using a vector.
* They are just here to illustrate the concept.
*/
struct TV_Show shows[20];
struct Movie movies[20];
};
考慮類似XML或JSON的東西,並學習序列化到/從中。優點是你有一個結構化的文件,但是你在計算出來的東西時仍然是可讀的。 –