• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

storing data in memory vs saving to DB

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.
0
mmingfeilam
Asked:
mmingfeilam
3 Solutions
 
sameer_goyalCommented:
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.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
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.
0
 
ee_reachCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now