Thread: Memory Issue...?

  1. #16
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>If you are, you deserve a freakin cokie or something...
    Heh, I agree... gee, that's actually a good idea, I wonder if there are any txt's out there (PDF looks difficult to handle)? *vanishes to search google*

    **EDIT**
    Done searching... wow, there's a lot of free bible software out there lol
    This seems to be a great place, although you'll need to convert the format to your own (which means you'll have to figure out the format it comes in).
    http://bibledatabase.org/bibles.html

    **EDIT2**
    Wow, it's just a textfile with headers for each verse! This could be fun...

    Code:
    (overall verse #) *tab* (book #) *tab* (chapter #) *tab* (verse #) *tab* (verse text)
    *repeat*
    Last edited by Hunter2; 08-09-2004 at 03:59 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #17
    Chad Johnson
    Join Date
    May 2004
    Posts
    154
    Ha...no way. That would be really error-prone. I found a text file of the King James Bible here. Maybe I could contact some Bible publishers and see if they'll give me something similar. Or maybe in order to use their version you'll have to pay [them] a little (hopefully not).

  3. #18
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    If you want to keep it simple, you could do this.

    Have a file named Genisis.txt with this in it

    Code:
    1:1 In the..
    1:2 blah
    I decided to try out a little test about how you would go about allocating memory and such for each book. (You could just load one book, or segments of books at a time)

    Code:
    #include <iostream>
    #include <fstream>
    
    char *fileBuffer;
    
    const long BookSize(char *book)
    {
      std::ifstream tempFile(book);
    	
      if(!tempFile.is_open()) {
        std::cout << "Error opening " << book;
        exit(1);
      }
    	
      tempFile.seekg(0, std::ios::end);
      long fileSize = tempFile.tellg();
      tempFile.close();
    	
      return fileSize;
    }
    
    void ReadBook(char *book, long fileSize)
    {
      std::ifstream file(book);
    	
      if(!file.is_open()) {
        std::cout << "Error opening " << book;
        exit(1);
      }
    	
      file.read(fileBuffer, fileSize);
    	
      file.close();
    }
    
    int main()
    {
      char book[50];
    	
      std::cout << "Type in the name of a Book: ";
      std::cin  >> book;
    	
      const long size = BookSize(book);
    	
      fileBuffer = new char [size];
    
      ReadBook(book, size);
    
      std::cout << std::endl;
      std::cout << fileBuffer;
      
      delete [] fileBuffer;
      return 0;
    }
    note this is just some example code.

    This is what happens

    Code:
    Type in the name of a book: C:\Genisis.txt
    
    
    1:1 In the begining, God created the heaven and the earth.
    1:2 Something about light.
    
    Where I have a text file named Genisis.txt in C:\ that contains

    1:1 In the begining, God created the heaven and the earth.
    1:2 Something about light.
    Last edited by Vicious; 08-09-2004 at 07:30 PM.

  4. #19
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Hey, that's a pretty cool textfile. It solves the problem of having to map numbers (book 1, book 2, etc.) to names (Genesis, Exodus, etc.). It might be a bit harder to parse though, since it has [ and : and other stuff like that... Well, good luck with it I'll be trying to write a converter program for the bible texts on the other site to a more convenient format (i.e. yours ).
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #20
    Chad Johnson
    Join Date
    May 2004
    Posts
    154
    Here's the program I threw together to convert that file (here) to the format I want.

    The only thing about the asv version at bibledatabase is that it includes the Apocrypha, and I'm not Catholic. I'm not going to bother with it, but if you want to that's cool.

    Now the thing I have to figure out is how to input my file correctly. I think I know how I am going to store it in memory (there might be a better way). I am thinking of either having one string for each chapter, or an array of strings of verses for each chapter, then I will have an array of pointers for each book pointing to those arrays, then I will have an array of pointers for the books pointing to the array of chapters.

    The only thing I really have to figure out is this. I store the location of the chapters in the header, with four bytes per chapter. Therefore, 00 7C D6 25 would be the location of one of the chapters in the file. In decimal, this number is 8181285. I don't know how to input this and store it as an integer. Also the hex values are stored backwards, like 25 D6 7C 00.
    Last edited by ChadJohnson; 08-10-2004 at 08:14 AM.

  6. #21
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>it includes the Apocrypha
    *snip* Hmm, where? It only has 66 books in it (I didn't bother comparing the texts, since that would be tedious), and I know the NIV old testament has 39 books, the NT has 27, for a total of 66...

    >>I think I know how I am going to store it in memory
    You could probably do that (it's only 4-5 mb), but I was actually thinking of just storing the verse locations in memory, then using seekg() to read the verses you need from the file when the time comes. That would spare you a lot of loading time (20-30 seconds on my computer).
    Last edited by Hunter2; 08-10-2004 at 11:03 AM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #22
    Chad Johnson
    Join Date
    May 2004
    Posts
    154
    Actually I think I was wrong about the ASV bible. It has 66 chapters and I couldn't find any keywords from the Apocrypha in it. I guess it's just worded differently and it threw me off.

  8. #23
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>I guess it's just worded differently
    Different translation?

    Anyhoo, back to my own converter prog... having tons of fun with nested classes and inherited functions that are probably unneccessary
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  9. #24
    Chad Johnson
    Join Date
    May 2004
    Posts
    154
    Hey I got the console version done. Some of the code is a little messy, and I have a little tweaking to do, but it works well. Try it!

    You will need to download the bible text here and run the makebibledb program with that file in the same folder to make the Bible file.

    I'm going to make a graphical version in the near future.

  10. #25
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    Me too!

    Hey yeah, I made one too. It's pretty simple, doesn't let you do searches or take notes or anything, but you can just type in a passage (i.e. "Amos 1:2") and it will display it. The main program is DigiBible, and the converter program is BFC (Bible FormatConvert). You can download the bible files for conversion from here.

    I'll edit this post when I've had a look at yours.

    **EDIT**
    Ok, had a look at your code. Just a few small things I'd like to point out...
    1) If this is C++, why use printf, malloc, free, FILE instead of cout, new, delete, ifstream?
    2) A book <= 0 still counts as valid, and same with chapter
    3) The Verse destructor has a memory leak - you forgot the [] after delete
    4) _BIBLESTRUCTURES_H_ is bad. According to the standard, anything with an underscore in front is reserved... so just knock off the front _ and you should be fine.

    Other than that, I can't spot anything to really nag you about (although you should probably try to use the standard C++ library instead of the C versions). Great job so far!

    Next, I'll have to download the bible file and do a running test... brb

    **EDIT2**
    Err, I downloaded the KJV bible and all, and followed your instructions, but when I run the makebibledb program, it doesn't work (it flashes across the screen for 1ms, and kjv.bbl appears in the folder, but kjv.bbl contains no data).
    Last edited by Hunter2; 08-23-2004 at 10:24 AM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help finding potential Memory issue
    By JoshNCSU22 in forum C Programming
    Replies: 9
    Last Post: 10-29-2008, 09:58 AM
  2. What's the difference?
    By Stonehambey in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 10:26 AM
  3. threads and memory issue
    By Anubhav in forum C Programming
    Replies: 6
    Last Post: 07-25-2006, 04:51 AM
  4. Memory Leak Help
    By (TNT) in forum Windows Programming
    Replies: 3
    Last Post: 06-19-2006, 11:22 AM
  5. Accessing Video Memory Information...need help
    By KneeLess in forum C++ Programming
    Replies: 8
    Last Post: 08-24-2003, 03:53 PM