Flat File Database in C++, Is it possible?
Flat File Database开发者_如何转开发 in C++, Is it possible?
Most flat file databases are written in C++. This is clear evidence that it is possible.
It is easy enough to make your own, especially if portablity - the ability to take a generated file and move it to another computer or use it with a different compilation of the program - is not required.
struct my_record_t {
...
};
int read(my_record_t& rec,size_t idx,FILE *f) {
if(0 > fseek(f,idx*sizeof(rec),SEEK_SET))
return -1;
if(1 != fread(&rec,sizeof(rec),1,f))
return -1;
return 0;
}
int write(my_record_t& rec,size_t idx,FILE *f) {
if(0 > fseek(f,idx*sizeof(rec),SEEK_SET))
return -1;
if(1 != fwrite(&rec,sizeof(rec),1,f))
return -1;
return 0;
}
Try tokyo cabinet: http://1978th.net/tokyocabinet/
精彩评论