- Home /
How to store a large amount of strings in memory?
Hi all, I'm planning to make a word game for Android. So I'm going to need a way to store a large amount of words/strings somehow. I really don't want my app to require internet access; I'd like everything to be saved in memory so that the user can use it at any time. I'm not entirely sure how many words I'm going to want to store yet but I might start with a couple hundred. Anyone have some "best techniques" for this kind of thing? (Including if I under-estimate my word count and/or expand my app?). I'm using JavaScript.
Thanks in advance!
Answer by Loius · Jul 20, 2013 at 02:21 AM
For dictionaries (not the dictionary data structure, but the dictionary that holds a whole bunch of words), you're better off using a tree structure. See this link for a decent tutorial on a tree-dictionary: http://www.dotnetperls.com/tree
The tree structure gets you auto-completion and spellchecking with reasonable ease as well, which is pretty handy.
Answer by trs9556 · Jul 20, 2013 at 01:58 AM
I don't use JavaScript so I'm unable to provide any examples but I can help with logic.
I suggest putting all strings into a string array. I also suggest making a separate class for just dealing with this huge amount of strings. Make some simple methods inside that class. The types of methods inside that class really depend on if your strings are static or dynamic.
If they are static then you won't need any methods to add/delete values from the array. Instead you will just need methods to get the current value for whatever index you need. So you'll need a method like GetString(int indexNumber) and just return the string value of that index. Because they are hard coded in(static) you will not need to create an instance of any sort. You can just create a generic class and just calling the methods.
If the strings are dynamic then there is a few more steps involved. For starters you will need to create an instance of the class. This can be as easy and an empty game object with the script attached. You will also need at least two additional methods, one to add a string to the array and one to delete. This completely depends on how you'll be using these strings but I think you get the idea.
I'm not sure why you are revolving this question about storing them in memory. You shouldn't really worry about this and just let Unity do its thing. Instead just create the functionality you'll need.
Answer by Deathcalibur · Jul 20, 2013 at 01:49 AM
http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use%3F
You want to you an ArrayList if you don't know the exact number of strings you will have in the beginning.
Answer by katie88 · Jul 20, 2013 at 06:09 PM
Ok awesome, thank you everyone. I will look into the suggestions. :)
I said "storing in memory" because I'm a bit of a n00b and don't know the exact terminology, lol. I just know that many games that have dictionaries and the like require internet to be used, which I find obnoxious. So I want everything installed on the device.
These are all great ideas. So thanks again!