-
June 23rd, 2006, 04:05 PM
#1
Senior Member
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
-
June 23rd, 2006, 08:49 PM
#2
Why not implement a linked list? Do a google on Linked List and you will find lots of information.
Cheers,
-D
If you spend more on coffee than on IT security, you will be hacked. What\'s more, you deserve to be hacked.
-- former White House cybersecurity adviser Richard Clarke
-
June 23rd, 2006, 09:10 PM
#3
Junior Member
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.
Only those who dare to fail greatly can ever achieve greatly.
-
June 25th, 2006, 05:59 AM
#4
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
-
June 25th, 2006, 07:02 PM
#5
Junior Member
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
Only those who dare to fail greatly can ever achieve greatly.
-
June 26th, 2006, 04:27 AM
#6
Junior Member
I suggest implement linkedlist too.
-
June 26th, 2006, 04:12 PM
#7
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
"When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
"There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
"Mischief my ass, you are an unethical moron." - chsh
Blog of X
-
June 26th, 2006, 06:13 PM
#8
Senior Member
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 ...
-
June 26th, 2006, 07:44 PM
#9
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?
ASCII stupid question, get a stupid ANSI.
When in Russia, pet a PETSCII.
Get your ass over to SLAYRadio the best station for C64 Remixes !
-
June 26th, 2006, 08:07 PM
#10
Senior Member
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 ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|