Guess of real array size in storage.

At the moment I'm storing an array of arrays in storage. Bit I want to be sure it doesn't exceed the size of 32kb.

The is an array made for each activity

It consists of 7 int values.

The time.today.value()

Seconds in HR zone 1 to 5

Total seconds.

These inner array are stored in the outer array and removed if the today value is older than 14 days.

The question is how many "activities" can I store before the 32kb is near?

  • First of all it probably can save some memory if instead of array of fixed size arrays you keep everything in 1 array and just do the math to index each element.

    Secondly it's not clear whether you are concerned about the file size or the memory it occupies when you load it, but probably in memory you'll win even more by flattening the nested arrays

  • To answer your second question first. In the API info it is written that there is a limit on the size of the Object Store that can vary between devices. Also, values are limited to 32 KB. So I guess the file size.

    To explain it a bit better I need to keep track of when the data(time in each HR zone) was created (the day). So if the activity data it's older than 14 days I can remove it. 

    I could store it as one array where every multiple of 6 starts a new stored activity.

    I also could store the activity data separately with a dynamic key name. And keep track of all the keys. In a key Array.

    Or the way I do it now.

    But to make a good choice I need a good estimate of the limit of the Object Store. And how to estimate the size of an individual array of arrays like have at the moment.

    For example if it is possible to store 100 sub arrays before I would reach 32kb. I have nothing to worry about and that would make life easier (no changes). But if it's more like 10 than that it's a problem.

  • Why don't you try it? Fill the array with some data, save, read back. If it works then try it for 28 days, etc... You'll find how many days you can save

  • I'll do that if no one has an idea. Also working on som other issues at the moment. 

  • I did run the following test (in the startup of my app):

    var rray = [2017250,1345, 4365, 345, 34534,1345];
    var testArray = [];
    for (var i = 0; i < 100; ++i) {
    testArray.add(rray);
    }
    Storage.setValue("testArray", testArray);
    var test = Application.Storage.getValue("testArray");
    System.print(test);

    This gave an error in the print test Line (even the sim gives that)

    Error: Out Of Memory Error
    Details: 'Failed invoking <symbol>'
    Half of the printout is in the log file and app did NOT crash.
    Using System.print(test[32]); did not raise any error's. 
    So this rises the question is this out of memory only a print thing or also something other functions could have? 
  • This test has at least 2 problems:

    1. you're adding the same array 100 times, it'll occupy significantly less memory (in the memory at least, because probably serialized in the storage it will be the same, but this is just my guess)

    2. your problem is probably not related to the storage. I bet you'll get the same error if you'd just try to print testArray instead. However because of #1 above note that probably test is much bigger than testArray.

  • So you suggest to do the test again but than use a dynamic filled array. For example [2*i,52+i, .....]  and so on.

  • doesn't have to be dynamic, just don't use the same array referenced 100 times, but instead create 100 arrays:

    var testArray = [];
    for (var i = 0; i < 100; ++i) {
       var rray = [2017250,1345, 4365, 345, 34534,1345];
       testArray.add(rray);
    }

  • i did it now lik this:

    var testArray = [];
    for (var i = 0; i < 50; ++i) {
    testArray.add([2017250+i,i, 2*i, 3*i, 345+i,13+2*i]);
    }
    Storage.setValue("testArray", testArray);
    var test = Application.Storage.getValue("testArray");
    System.print(test[23]);

    This worked without a problem. at 80 and 100 it gave an error in the simulator. so I went for 50. I think 50 activities in 14 days should be safe enough don't you think.

  • Sounds enough. Especially that probably you could even go higher, 'cause you don't seem to have a problem with storing or reading it but only printing which you won't do in the real app.

    You could even do this:
    for (i = 0; i<100; i++) {print(test[i]);}

    this way you can see if the values you read are correct. IMHO they will be.