I just run into "out of memory". I tried to figure out where it happend and what can i optimise to prevent this. I saw that i had around 300 units (Junks of 20 bytes) free before i called a few cascaded functions that converts a string into an array of bytes, calculates checksums length and returns it.
To understand the usage in general i run the following test:
console.log(process.memory());
str='Hi Gordon, a string with 80 characters, that will be converted to an array of B';
console.log(process.memory());
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi Gordon,
I just run into "out of memory". I tried to figure out where it happend and what can i optimise to prevent this. I saw that i had around 300 units (Junks of 20 bytes) free before i called a few cascaded functions that converts a string into an array of bytes, calculates checksums length and returns it.
To understand the usage in general i run the following test:
console.log(process.memory());
str='Hi Gordon, a string with 80 characters, that will be converted to an array of B';
console.log(process.memory());
Output:
{"free":1782,"usage":18,"total":1800,"history":3,"stackEndAddress":536909496,"flash_start":134217728,"flash_binary_end":134435552,"flash_code_start":134443008,"flash_length":262144}
{"free":1775,"usage":25,"total":1800,"history":14,"stackEndAddress":536909496,"flash_start":134217728,"flash_binary_end":134435552,"flash_code_start":134443008,"flash_length":262144}
7*20 bytes=140 bytes for a string of 80 chars. Nothing special.
Now i created an array of 80 bytes this way:
console.log(process.memory());
bytes=[];
for (var i = 0; i < 80; ++i) { bytes.push(i); }
console.log(process.memory());
The output:
{"free":1782,"usage":18,"total":1800,"history":3,"stackEndAddress":536909496,"flash_start":134217728,"flash_binary_end":134435552,"flash_code_start":134443008,"flash_length":262144}
{"free":1618,"usage":182,"total":1800,"history":15,"stackEndAddress":536909496,"flash_start":134217728,"flash_binary_end":134435552,"flash_code_start":134443008,"flash_length":262144}
That array needs 164 chunks of 20 bytes = 3280 bytes, nearly 10% of the available memory!?
Is this as expected ?
Thanks
Sacha