2

Pretty much as the title says.

I want to launch my Android app, using ObjectBox, but I'd like the data to be prepopulated in the boxes.

Can I package both data.mdb and lock.mdb inside the app, from data I've created during development?

Or is there device specific stuff in there that will need to be generated on each specific device individually.

EDIT -

On checking how big my data.mdb file is it's HUGE!!! I am trying to store a dictionary of words. It has 370k 'rows' each containing a single word, and linking to another box which has a single value in. The file is 171Mb big!! That's outrageous!!!

I have it indexed, and have read that indexes make things large. Is this the case? Is there anything I can do about it?

Russ Wheeler
  • 2,590
  • 5
  • 30
  • 57
  • Hi, about the size I need to ask a couple of questions: which ObjectBox are you using? What was the version you initially created the db? Did you try recreating the db with ObjectBox 2.0? How many "words" do you store? What's the average length of words? – Markus Junginger Aug 08 '18 at 10:13
  • PS.: How many indexes do you have? – Markus Junginger Aug 08 '18 at 10:24
  • I created it a couple of days ago, using 2.0. I have 370k words. The average length... No idea, it's all the words in the English language! I guess average would be around 6-8? Only have one index on the word itself – Russ Wheeler Aug 08 '18 at 11:28
  • 1
    I stripped out more things to try and make it cleaner and got it down to 112Mb. This is from a text file that is only 4Mb big. I must be doing something wrong – Russ Wheeler Aug 08 '18 at 11:29
  • 1
    A dictionary is not the perfect fit to store as individual objects, there are more space efficient ways to store it. Are any properties associated with words? – Markus Junginger Aug 08 '18 at 13:10
  • Hey, it's ok, I managed to get my original solution working. Just using a plain old HashMap. I turned to ObjectBox because I used it in my last app, and will no doubt use it again in this one. I guess not for a dictionary though :D – Russ Wheeler Aug 08 '18 at 19:53
  • Just curious: how much memory does the HashMap use? You could optimize memory usage if you wanted: pre-sort the strings in your source (txt file?) and put them in a String array. Then do binary search on it. – Markus Junginger Aug 09 '18 at 08:32
  • I haven't been able to workout how much memory the Hashmap takes up. I'm using Android Studio and the new profiler tool seems to crash AS when I click to take a heap dump! – Russ Wheeler Aug 09 '18 at 16:11

1 Answers1

3

As to the original question: yes, you can ship your app with an initial data file. You can prepare an ObjectBox database with all the data you need and then grab the data.mdb from the db director (default name is "objectbox").

The BoxStoreBuilder offers the overloaded method initialDbFilethis:

initialDbFile(java.io.File initialDbFile)

initialDbFile(Factory<java.io.InputStream> initialDbFileFactory)

Thus, you can either provide a File or an InputStream.

Markus Junginger
  • 6,950
  • 31
  • 52