-
C++ Database
Aloha,
Here is my problem ... I want to make my own DB in C++ without any external drivers like BDE . The problem is that the count of the records is unknown. In pascal I use record. But how can I do it in C++. I supose to use array of structs, but the size of the array must be const ...
Please, if somebody knows - give me idea, exaple, source ... something
-
Why not implement a linked list? Do a google on Linked List and you will find lots of information.
Cheers,
-D
-
The size of array in c++ can be variable,but it must be dinamic allocation.Use keyword new to do that and you must be familiar with pointers.For example dinamicaly allocated array of int would be:
...
int n;
cin>>n;
int* array=new int[n];
...
Now you can use it as any other array, so this works fine (if n>=1):
int p=array[1];
Hope you can make it ;).Search google for it a bit more, you will find it for sure.
-
IIRC, 'n' cannot change once the array is declared. Thus, this isn't really a dynamic array, just allowing you to choose the size of the fixed array at runtime. For databases, what you should be looking at are implementing link lists, stacks and queues. Also, if this database is going to be designed to hold more than a few hundred records, you should read up on hash tables as well.
Also, remember that linked lists are quite an inefficient way of storing large numbers of record. A vector coupled with a hash table would be much much better.
An excellent (if technical) book to read to learn data structures is "Data Structures Using C and C++" by Yedidyah Langsam, Moshe J. Augenstein and Aaron M. Tenenbaum. The book makes an excellent guide to the world of data structures.
Cheers,
cgkanchi
-
Well if he wants to use "arrays of structs", he must be familiar with dynamic allocation it was just an example... He could make it with pointers in struct sth. like this:
...
struct SomeStr{
...
SomeStr* Link;}
...
And than dynamicaly allocate new nodes,and make the Link point to the fresh allocated struct.So it is not impossible I guess, and it is faster than vectors but more complicated of course.
Cheers
-
I suggest implement linkedlist too.
-
I suggest you do a bit more research into data structures beyond arrays and linked lists. I'd also look into what other people have used to do their implementations.
AFAIK a better structure to use for a database implementation is the b-tree. Arrays give performance problems when adding/removing/moving data that isn't at the end, linked lists can be slower to search....
http://www.bluerwhite.org/btree
-
Hello,
I took a look on linked lists and hash tables, but what I don't understand is can I change the hash table size in run time, without any collisions ...
-
Why write your own database when you can use the excelent Berkeley DB ( http://www.sleepycat.com/products/bdb.html )
I've used it and it's very fast and efficient.
But you wanted without 'drivers'.. does a couple of dlls count as a driver?
-
I don't want drivers, because on the pc where will work this program, already has BDE. When I tried to use new version of BDE (Because the running version is very old) for example it causes system to hang up or the program is not working properly. But i'll try this engine ...