Capacity of MC on VA-HR

I am evaluating the VA-HR as a platform to host my pebble app.
The Programmers Guide lists some run-time errors such as :

  • Too Many Timers (what is the limit?)
  • Too Many Arguments (is 9 the limit?)


I know this isn't exhaustive, eg. Too Many Objects Error:
Before committing resources to porting the app, I am looking for a comprehensive specification of the actual capacity and limits of the platform.
Is such a document available?
  • There is no comprehensive document that describes the limits, but in my experience...

    * Too Many Timers (what is the limit?)

    The maximum number of concurrent timers is 3. You can work around this by implementing a timer queue or wheel. Use a single timer to manage the queue/wheel, and you'll only be limited to the available objects and memory.

    *Too Many Arguments (is 9 the limit?)

    I'm not sure what the limit is. I would think that it would be uncommon to run into this limit, and if you do the solution is quite simple... pass the arguments in an object of some sort (an instance of a class of your own, a Lang.Array or Lang.Dictionary).

    I know this isn't exhaustive, eg. Too Many Objects Error

    I believe this is device dependent, but I do recall finding the limit in testing on a ConnectIQ 1.x device to be 256.

    Travis
  • With timers, I only use one (with it firing every second many times), and like Travis said, do things based on that. Each second update the display, and by tracking a count, easily do something every 15 minutes by counting ticks, for example.

    I think I hit "too many arguments" only once, and as Travis suggested, just passed the arguments in an array. A minor change to the call and the function itself.

    Number of objects, as Travis said, is 256 at least on some devices. The only time I had an issue was when I was creating a large 2 dimension array (if I recall, [2x120] was where I got the error), and by a simple restructuring of the array (one dimension, and twice the size - [1x240]), no error - I guess what I'm saying is that how you handle vars can help a great deal with your objects count if you have an issue. (BTW, that same array is actually something like [1x1800] right now, with no error.
  • I'm trying to explore memory capacity and internal stats more by building an array of different elements till it crashes.

    • a) With elements as Dictionary containing five with string-named elements,
    • b) with elements as Dictionary containing five with symbol-named elements,
    • c) with elements as array containing five numeric elements

    Results are:

    [TABLE]
    [TR]
    [TD][/TD]
    [TD]elements created
    before crash[/TD]
    [TD="align: center"]usedMemory[/TD]
    [TD="align: center"]freeMemory [/TD]
    [TD="align: center"]totalMemory[/TD]
    [TD]Crash report[/TD]
    [/TR]
    [TR]
    [TD]Before[/TD]
    [TD][/TD]
    [TD="align: right"]33232[/TD]
    [TD="align: right"]91896[/TD]
    [TD="align: right"]125128[/TD]
    [TD][/TD]
    [/TR]
    [TR]
    [TD]a) With Dictionary with named keys[/TD]
    [TD="align: right"]77[/TD]
    [TD="align: right"]61040[/TD]
    [TD="align: right"]64080[/TD]
    [TD="align: right"]125128[/TD]
    [TD]Too Many Objects Error[/TD]
    [/TR]
    [TR]
    [TD]b) With Dictionary using :symbol keys[/TD]
    [TD="align: right"]379[/TD]
    [TD="align: right"]123480[/TD]
    [TD="align: right"]1648[/TD]
    [TD="align: right"]125128[/TD]
    [TD]Out Of Memory Error[/TD]
    [/TR]
    [TR]
    [TD]c) with Array of arrays[/TD]
    [TD="align: right"]469[/TD]
    [TD="align: right"]58080[/TD]
    [TD="align: right"]67040[/TD]
    [TD="align: right"]125128[/TD]
    [TD]Out Of Memory Error[/TD]
    [/TR]
    [/TABLE]



    I guess a) crashed because of a limit to the number of string objects in the Dictionary names
    b) looks like it just ran out of memory.
    c) is strange, as freeMemory is still reporting 67040 bytes free. I wonder what's being counted here. Does MC implement stack and heap like in C? Is it creating the array in the stack and hitting a limit there?
  • You're seeing what I mentioned about how you store your data, and simulating it on a 2.x device (va-hr,735,fenix Chonos). You'll hit the errors sooner with a 1.x device.

    Dictionaries aren't cheap when it access, and "array of arrays" is the multidimension thing I mentioned.

    Lets say you're thinking [4x100] That could be 5 arrays or 101 arrays for [100x4] but could be only one array of 400 in either case, where you just do indexing into it such as [i*100+j] or [i*4+j]
  • I hear what you say about multi-dimensional arrays, even if I don't understand the why!

    But... what I would like to know is how to interpret the usedMemory and freeMemory I reported above. How can I be hitting the memory limit when it's reporting freeMemory of 67040, or, more specifically, how can I use the stats object to accurately predict when my app is about to crash with an Out of Memory error?
  • I hear what you say about multi-dimensional arrays, even if I don't understand the why!

    Because objects in MonkeyC are implemented as handle-body and are reference counted. Consider this code...

    var array = new [100];
    for (var i = 0; i < 100; ++i) {
    array= new [2];

    for (var j = 0; j < 2; ++j) {
    array[j] = i * 100 + j;
    }
    }
    [/code]

    This makes a 2x100 array (2 cols, 100 rows). The outer object, named array is a reference-counting handle to an actual array implementation that is allocated on the heap. That implementation object has a reference count, and 100 handles. Each of those handles reference another array implementation, each with their own reference count and 2 handles. So, for an outer array with N elements, you have N reference counts that you don't need, and those take up space.

    how can I use the stats object to accurately predict when my app is about to crash with an Out of Memory error?

    I'm sorry, I don't know the answer to this. Obviously, if your app reaches the situation where the amount of contiguous free memory is less than the system requires, you're going to get a crash. Theoretically as the heap gets fragmented, that can cause problems where memory is available, but can't be used as it isn't contiguous. How to avoid this would depend on how the heap is implemented, but if you can allocate your memory in large blocks and re-use it, that would be good.

    Travis
  • I'm still trying to find how to monitor my memory usage with System Stats.
    I have this loop which crashes in the creation of the tracks[465] element. I understand that there are memory limits and that there are techniques to manage this usage, but I'm looking for a way to monitor the memory during development.

    var tracks = new [500];
    for (var i=0; i<500; i++){ //
    tracks= [
    12345,
    -33.234,
    155.123,
    5.4,
    123
    ];

    System.println(i+ ", "+ System.getSystemStats().usedMemory+
    ", "+ System.getSystemStats().freeMemory+
    ", "+ System.getSystemStats().totalMemory);

    }[/CODE]

    It reports as follows:
    ....
    461, Used:62160, Free: 62960
    462, Used:62208, Free: 62912
    463, Used:62256, Free: 62864
    Failed invoking <symbol>
    Out Of Memory Error

    Note, it's still reporting 62864 free when it crashes.
    When I limit the loop to i<=463, the app starts and the simulator reports Mem:46.2/122kB, Peak:61.2kB (but crashes after a couple of minutes simulating data with too many objects error)
    So, what is going on? Is it memory fragmentation?
    How can I manage that?
  • Looks to me that you could be actually running out of objects (that multi-dimension array thing) but it's reporting out of memory. (out of objects used to be reported as out of memory, and maybe there was a place they missed making the change)
  • And that would be because each row of my array is an object, right?
    So, next question....Is there any way to interrogate the number of objects?
  • Travis post explains it, as you are trying to make a 500x5 array. In my post I explain how to use a a single array (var tracks=new [500*5]) and that should avoid the issue.



    There's no way to display the object count used/avail in CIQ. It might be nice to have this, but it's not currently there.