storing data in memory vs saving to DB

Posted on 2012-09-16
Last Modified: 2012-10-02
i am reading from a text file and creating a dictionary from the words there.  is it better to create the dictionary in memory or save to a DB and retrieve it later.  what about saving to a file?  the current text file is not that big, ~2000 lines, 8000 words.
Question by:mmingfeilam
    LVL 5

    Assisted Solution

    The decision to choose between in-memory storage or db or text file will depend on your answers to the following:

    1. For how long do you want the dictionary to persist?
    2. What will the frequency of you referring this dictionary created in your program?
    3. For now it is 2000 lines. Is there a chance that this can grow?

    Now, if you want the dictionary persist forever, and you will just fetch the data in dictionary and use it over and over again, use either the file or db

    But if you want to have the dictionary available for a small amount of time, may be go for the in-memory storage.
    LVL 40

    Assisted Solution

    by:Jacques Bourgeois (James Burger)
    A database would probably overkill with only one table.

    A file would probably be sufficient, and is more easily portable. You can copy it in a pinch.

    Then it depends on the use of the dictionary once it is created. If it is only for consultation, then the file should be sufficient. If it is used to check other text, then you might get a better performance loading it in memory because searches would be better that way.

    Tell us more about what you intend to do with the dictionary, we might come up with other ideas.
    LVL 8

    Accepted Solution

    I would also ask how many of these dictionaries are going to be active at any given time.  

    E.g., will you have multiple users starting this program and each would have his own copy of the file and the text be different for each one?  If so, that could end up being a lot of data in memory.

    If you'll only ever have one copy running at any given time, then I would want to hear more about what you intend to do with it.

    Another consideration - how important is it to have this file later?  E.g., is it mission critical to have a copy of the data saved somewhere when your program exits (whether your program exits intentionally or unintentionally.)  That is, is the file that you are reading from readily available every time you start the program or could the initial file vanish and what are the consequences if the file isn't there at start up.

    Lots of questions, need more info to give a helpful answer.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now