C++ Database
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: C++ Database

  1. #1
    Senior Member
    Join Date
    Jul 2003
    Posts
    166

    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
    BGDevS
    [gloworange]www.peaksoft.info [/gloworange]

  2. #2
    Senior Member
    Join Date
    Jul 2001
    Posts
    420
    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

  3. #3
    Junior Member
    Join Date
    Aug 2004
    Posts
    14
    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.

  4. #4
    Antionline Herpetologist
    Join Date
    Aug 2001
    Posts
    1,165
    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
    Buy the Snakes of India book, support research and education (sorry the website has been discontinued)
    My blog: http://biology000.blogspot.com

  5. #5
    Junior Member
    Join Date
    Aug 2004
    Posts
    14
    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.

  6. #6
    Junior Member
    Join Date
    Nov 2002
    Posts
    21
    I suggest implement linkedlist too.

  7. #7
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    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

  8. #8
    Senior Member
    Join Date
    Jul 2003
    Posts
    166
    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 ...
    BGDevS
    [gloworange]www.peaksoft.info [/gloworange]

  9. #9
    Leftie Linux Lover the_JinX's Avatar
    Join Date
    Nov 2001
    Location
    Beverwijk Netherlands
    Posts
    2,535
    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 !

  10. #10
    Senior Member
    Join Date
    Jul 2003
    Posts
    166
    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 ...
    BGDevS
    [gloworange]www.peaksoft.info [/gloworange]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides