0

I have very big boolean array data.

How can i save memory and load this data quickly in android?

Joowon Ryoo
  • 59
  • 2
  • 9

2 Answers2

2

150 items of boolean are small amount of data for conventional mobile devices. You can save more than 1000 items at once within 1 second.

Method 1

Realm already supports byte[] as a datatype. You can use it by converting boolean array into byte array.

Method 2

As you know, boolean is just 1-bit(binary) data. There's lots of case to handle such bits, but for me, I love to handle it in naive manner.

  1. Let say you have 160 items of boolean.

    • true, false, ..., true, false
    • It can be converted to 1 or 0: 1010101....1010110
  2. 1 hex string contains 4 bits.

    • 1010 1110 0110 1100 can be expressed into AE6C
  3. Likewise, 160 bits can be converted into 160/4=40 strings.

  4. Just save 40 length strings to Realm or SharedPreference.

  5. Want to load? no problem. Convert 40 length strings into 160 length boolean array.

I think it could consume less than 100ms as those converting process is pretty fast in modern mobile CPUs.

Community
  • 1
  • 1
Youngjae
  • 24,352
  • 18
  • 113
  • 198
0

Here are 4 possible soluzions:
1.) You can serialize an Object and save it to a file.
2.) You can use Gson library and convert the object to JSON and save it to a file or in preferences.
3.) You can use Realm library which is fast. They even claim that on some operations they are faster than SQLite.
For solution 1 see https://stackoverflow.com/a/33896724/1502079
For solution 2 see https://stackoverflow.com/a/16436363/1502079

Community
  • 1
  • 1
vovahost
  • 34,185
  • 17
  • 113
  • 116