You are reading a single comment by @fanoush and its replies. Click here to read the full conversation.
  • There is one more thing about strings I did not know.
    When you read via var t=require("Storage").read("test.js") then t is native string = it points to flash memory, not RAM
    when you load/execute this test.js file

    var s
    var s2
    var s3="native string"
    function test(){
    s=atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
      s2="Hello"
    }
    

    via load("test.js") then it can be seen via trace()

     #18[r1,l2] Name String [1 blocks] "s3"    #19[r1,l0] String [2 blocks] "native string"
      #21[r1,l2] Name String [1 blocks] "test"    #22[r1,l0] Function {
          #24[r1,l2] Name String [1 blocks] "\xFFcod"        #23[r1,l0] NativeString [1 blocks] "s=atob(\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\")s2=\"Hello\""
        }
    

    that the function body is still native string and points to flash however the s3 string is normal string in RAM, also when you execute the test function the s2 also is a string in RAM. This I did not know.

    I was expecting that like test function body and stuff read via Storage.read those s2,s3 strings would be native strings pointing to flash not taking any RAM. However it is not like that and never was(?) Works like that before and after this string tokenisation and also tested wit some older versions like 2.16.

    If such optimization was there I was wondering what could happen with such strings when parsing or execution of code with these new features just added here but as it is not there there is no issue :-)

    I guess this optimization I thought was already there could be added too? At least when the string is there full in verbatim and does not contain escape characters e.g. 'aaa"aaa' could point into native part aaa"aaa but it won't work for "aaa\"aaa"

    Then in future case of WebIDE replacing atob() with big binary strings which would be stored directly inside the file in flash, those strings would also be in flash but without that they would be in RAM like shown here(?)

    I tested this in device with no SPI flash so Storage is native nrf52 flash so maybe for BANGLE2 it may be different?

    EDIT: I retested with Bangle 2 and the only difference is that function body is "FlashString" not "NativeString" but s2,s3 are in RAM too. But anyway with pretokenized strings this feature may be easier to implement and when done by IDE also the tokenized "aaa\"aaa" would be simple string that could be Flash/NativeString (when parsed from code that is also such string = storage file).

About

Avatar for fanoush @fanoush started