I am programming a datafield, which I wish to keep in datafield format, however there are memory and execution limitations which I am hitting, and I wanted to get some feedback concerning what you (all) thought was best practices...
1. I have divided some of the calculations up so that execution time isn't all packed into the Compute function, but some is also executed in the onUpdate function as well. This seems to be a good idea.
2?. Would anyone recommend utilizing a timer function to postpone execution for a partial second? ..for something which keeps going over the limit of executions, and causing the watchdog to crash the datafield (on the sim)
3. I have taken steps to minimize the creation of extra variables because they use a lot of memory, but it comes at the price of more calculations/executions, therefore that is another trade off I must consider. If I remove certain clarity variables, I have to add calculations/executions, which also cost memory, and increase the risk of alerting that damned Watchdog.
4. Another thing I have done is to transfer less-frequently-used variables into a single string variable and am using a function like the below one to access it. This accounts for some of my high execution rates - because this simple variable-checking function is heavy on usage, no doubt.
function getvar(x) {
return (myVariable.substring(x, x+1).equals("1") ? true : false );
}
//during Compute etc
if (getvar(2) ) { // not sure the "cost" of this operation
// do something...
As you can see, this function uses the .substring(x,y) and the .equals(y) method. Not sure how good it is compared to "==" or ">", etc other operators.
5. After having the Watchdog shut my simulated datafield down a number of times, I am now thinking more direct routes to checking variables is better, so now that previous check is simply a "if (xxx.substring" operation, I don't call that other function at all.
6. Since all variables are "objects", is there any preferred type of variable or operation which is preferred from a memory/execution-time standpoint? For instance, in C the documentation I have read indicates that shifting operations ">>" are quicker than traditional multiplication because they translate to binary shifting operations cleanly, whereas multiplication does not.
7. Another possible way to save memory, is to call "getProperty" function more often instead of creating a variable and loading the data at the beginning of program execution (as shown below).
if ( Application.getApp().getProperty("A").substring(6,7).equals("1") ) {
//playtone...
}
// alternative seems to create "copy" of the data, but is this way really ~better~ in terms of execution?
var earlyDeclaredVariable = myApp.getProperty("A").substring(6,7);
//.....
if (earlyDeclaredVariable == "1") {
//playtone...
}
so, is it a hefty price to call that "getProperty" function? (my program does require obtaining some data from settings). From the "View Active Memory" window it looks like I'm saving memory because instead of having three (what looks like copies!) of the data I only have two!!!
.....I have a few boolean data types, and some other floats and integers, however I was hoping I could figure a way to efficiently conduct this program, as a datafield. Is there an added benefit to using boolean data types, or maybe I should just stick with more qualitative variables so as to minimize unnecessary re-formating/organizing of data
.....I want to target as many Garmin watches as possible, and I believe it is possible, but I want to increase my memory and execution efficiency so that the user can use it more effectively... Right now I know a user can input about 8 points into my datafield, however I haven't tested the limits, and I was hoping to get a whole lot more, maybe like 30, if you know what I mean.
.....I've already got no variables in my onUpdate portion due to file exclusions, and it works across most Garmin platform (on the sim), so I'm happy for that.
.....Anyways, a bigger question is this: Is there any summary/information page which contains the memory and execution costs associated with each of these activities? Seems like such a page would be of great use to us "small-platform" programmers... I suppose I could program my own unit tests to discover more about this, but I was hoping there was some documentation or guidance available somewhere, that might be shareable... not to re-invent the wheel and all.
.....(my watch is a 630, so I have the added benefit of programming for the platform with one of the smallest memory footprints I think; I definitely want this datafield to work on my own watch!)
.....I have read somewhere in these forums that people have analyzed the .IQ file as a way to increase memory efficiency and program efficiency. I would be interested in hearing how one goes about this, although I would rather not have to break open the code to that extent, yet.
That watchdog is tough! :eek: