开发者

Flat File Database in C++, Is it possible?

开发者 https://www.devze.com 2022-12-17 10:11 出处:网络
Flat File Database开发者_如何转开发 in C++, Is it possible? Most flat file databases are written in C++.This is clear evidence that it is 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/

0

精彩评论

暂无评论...
验证码 换一张
取 消