10-11-2019 01:19
10-11-2019 01:19
I am building a custom clockface where I need more than 500 static strings which I put in an JSON-array.
Stored on file without whitespaces the JSON-array is about 9KB in size.
I am now getting Fatal Jerryscript Error: ERR_OUT_OF_MEMORY
I guess this is because of the array, when I limit the array to a few elements only, the clockface is working in the simulator
.
So I am looking into alternatives of storing those strings in my clockface.
But before doing this I want to make sure I am not running into other memory constraints again.
1. Is there a way to deploy 500 files, like I can deploy images using the Resources directory?
I would like to create 500 files, each file storing a string and when creating the .FBA file I want the 500 files to be part of my clockface. Is that possible?
2. Instead of storing 500 strings in the JS code I consider to create 500 images with the strings already drawn and store those images in the Resources directory.
Is that even possible to store 500 images in the Resources directory? What are the storages limitations for apps or clockfaces?
3. What is the maximum memory a clockface (or an FitBit app) can handle?
4. Should I use the settingsStorage? What is the maximum size the settingsStorage can handle?
5. Do you have any other suggestions how to store 500 static strings in a clockface (or an App)?
Are there any memory differences between an app and a clockface?
Answered! Go to the Best Answer.
10-21-2019 01:42
10-21-2019 01:42
1. I'd probably try using localization to hold the strings.
https://dev.fitbit.com/build/guides/localization/
2. 15mb total size, including your code
3. 64kb
4. No, 5mb
5. See 1.
10-11-2019 01:24
10-11-2019 02:02
10-11-2019 02:02
Same problem . Used 16k of the 64k of Jerryscript memory. But ran out of memory with an array of 180*4 numerical and a file of the same size.
now I’m testing the system memory to see of I can find any solution.
10-11-2019 03:01
10-11-2019 03:01
According to memory.js.used the footprint of my clockface is 29872 bytes out of 65528.
So how come I can't add the JSON array which is 9KB in size?
10-11-2019 03:06
10-11-2019 03:06
Check the memory level immediately before and after attempting to create the array.
Too many SVG elements can be a problem.
It is also possible to get a stack overflow, although that may give a different message.
10-11-2019 03:09
10-11-2019 03:09
I also have a suspicion that javascript stores strings as 16-bit characters (regardless of encoding).
10-11-2019 10:09 - edited 10-11-2019 11:21
10-11-2019 10:09 - edited 10-11-2019 11:21
Not directly related to your problem, but may help - FitbitOS JavaScript Optimization Guidelines:
https://github.com/gaperton/ionic-views/blob/master/docs/optimization-guidelines.md
In most cases, you can assume one character in a string to be 1 byte. But it may as well be 2 bytes. Assume your average string length is 30 characters, 2 bytes each, 60 bytes per string, multiplied by 500, roughly 30 KB.
You can actually count it, see:
https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder
https://stackoverflow.com/questions/5515869/string-length-in-bytes-in-javascript
10-11-2019 13:57
10-11-2019 13:57
10-17-2019 06:54
10-17-2019 06:54
If anyone wants to know how I solved my problem:
I created 300+ png-images with those 500 static strings prerendered and stored them in the resource directory. Size 2.2 MB. Instead of setting the .text property of a Text element I change the .href of an Image element instead. Not what I would have done in ASP.NET Core but it worked in the Jerryscript environment. One advantage is that I now can choose among my fonts from my Windows 10 computer when creating the text strings. One drawback is that app.fba is 4.23 MB in size and takes some minutes to install on my Fitbit Ionic.
10-21-2019 01:42
10-21-2019 01:42
1. I'd probably try using localization to hold the strings.
https://dev.fitbit.com/build/guides/localization/
2. 15mb total size, including your code
3. 64kb
4. No, 5mb
5. See 1.
10-28-2019 21:59
10-28-2019 21:59
Are the strings all the same length?
9KB JSON would suggest they are only a few characters apiece
You could use a single string and pull the relevant parts out with something like
currentVal = buffer.substr(x*size,size)
Then it's only one string with one instance of string overhead
Regards,
Reign
Regards,
10-30-2019 07:13
10-30-2019 07:13
I needed an array of string arrays like this. Some indexes might have zero strings and some might have up to three strings. Depending on the index chosen I need to show zero, one, two or three strings in my clock face.
{
"myArr": [
{
"N": []
},
{
"N": [
"Short string 1"
]
},
{
"N": [
"Short string 21",
"Short string 20"
]
},
{
"N": [
"Short string 3"
]
},
{
"N": [
"Short string 42",
"Short string 40",
"Short string 41"
]
} ...
10-30-2019 20:00
10-30-2019 20:00
Hello @GeekBit ,
Your test object is an array of objects containing an array of strings. Each level consumes memory.
Simpler objects consume less, sometimes far less.
Example, an array of simple strings: