Note: I've discovered a bug here, which is that process.memory().history (which is the amount of memory used for the command history) is being calculated wrong, and so that knocks all the calculation of 'free' memory out. My info below is with a development version that now has this fixed. When 1v48 comes out that should have the fix in.
What I think is happening is that the script is being executed, and is generating variables/functions which are using up more space than just the individual characters. If you just had one function that wasn't executed then the situation would be a lot better.
So the code above (which, incidentally is 490 characters) uses 35 blocks in total which is 700 bytes.
Of that:
blocks
use
1
The function name foo
1
A Block saying 'I'm a function'
1
A Block saying 'I'm a function's code'
31
String data, as Espruino uses 4 bytes out of each 20 byte block for other stuff (490*/16=31)
1
When we typed process.memory() to query the memory, it added one block named process because we referenced it and it wasn't there before. This is something that could be fixed later though
You can type trace() (a debug tool for developers) which outputs the raw structure of the interpreter's data, and that might help to explain where your memory is going...
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.
Yes, memory units of 20 bytes is right. Just for anyone else:
Note: I've discovered a bug here, which is that
process.memory().history
(which is the amount of memory used for the command history) is being calculated wrong, and so that knocks all the calculation of 'free' memory out. My info below is with a development version that now has this fixed. When 1v48 comes out that should have the fix in.What I think is happening is that the script is being executed, and is generating variables/functions which are using up more space than just the individual characters. If you just had one function that wasn't executed then the situation would be a lot better.
For instance:
So the code above (which, incidentally is 490 characters) uses 35 blocks in total which is 700 bytes.
Of that:
foo
process.memory()
to query the memory, it added one block namedprocess
because we referenced it and it wasn't there before. This is something that could be fixed later thoughYou can type
trace()
(a debug tool for developers) which outputs the raw structure of the interpreter's data, and that might help to explain where your memory is going...