tags:

views:

124

answers:

3

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

+3  A: 

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;
}
Will
Well i thought they were only in use in php Sorry
H4cKL0rD
A: 

Yes.

KennyTM
+1  A: 

Try tokyo cabinet: http://1978th.net/tokyocabinet/

Long Cheng