• I got it running this way.
    Simple board gives me 2000 vars
    Board with additional PSRAM gives me 20000 vars.
    @DrAzzy, we could use 65500 here too

    ESP32.py

     'variables'                : 2000,
     'variables_psram'          : 20000,
     'variables_mode'           : "malloc",             ESP32 uses malloc
    
    

    jsvar.h

    extern unsigned int jsVarsSize;
    

    jsvar.c

    [#ifdef](https://forum.espruino.com/search/?q=%23ifdef) RESIZABLE_JSVARS
    JsVar **jsVarBlocks = 0;
    unsigned int jsVarsSize = 0;
    [#define](https://forum.espruino.com/search/?q=%23define) JSVAR_BLOCK_SIZE 4096
    [#define](https://forum.espruino.com/search/?q=%23define) JSVAR_BLOCK_SHIFT 12
    [#else](https://forum.espruino.com/search/?q=%23else)
    [#ifdef](https://forum.espruino.com/search/?q=%23ifdef) VARIABLES_MODE_MALLOC
    unsigned int jsVarsSize = 0;
    JsVar *jsVars = NULL;
    [#else](https://forum.espruino.com/search/?q=%23else)
    JsVar jsVars[JSVAR_CACHE_SIZE];
    unsigned int jsVarsSize = JSVAR_CACHE_SIZE;
    [#endif](https://forum.espruino.com/search/?q=%23endif) //end VARIABLES_MODE_ALLOC
    [#endif](https://forum.espruino.com/search/?q=%23endif)
    ......
    void jsvInit() {
    [#ifdef](https://forum.espruino.com/search/?q=%23ifdef) RESIZABLE_JSVARS
      jsVarsSize = JSVAR_BLOCK_SIZE;
      jsVarBlocks = malloc(sizeof(JsVar*)); // just 1
      jsVarBlocks[0] = malloc(sizeof(JsVar) * JSVAR_BLOCK_SIZE);
    [#else](https://forum.espruino.com/search/?q=%23else)
    [#ifdef](https://forum.espruino.com/search/?q=%23ifdef) VARIABLES_MODE_MALLOC
      jsVars = (JsVar *)malloc(sizeof(JsVar) * jsVarsSize);
    [#endif](https://forum.espruino.com/search/?q=%23endif)
    [#endif](https://forum.espruino.com/search/?q=%23endif) 
      jsVarFirstEmpty = jsvInitJsVars(1/*first*/, jsVarsSize);
      jsvSoftInit();
    }
    

    build_platform_config.py

    if board.info["variables_mode"]:
      codeOut('#define VARIABLES_MODE_'+board.info["variables_mode"].upper() + ' // mode for allocating memory, standard is statically assigned');
      codeOut('');
    ...
      if board.chip["class"]=="ESP32":
        codeOut("#define JSVAR_CACHE_SIZE_PSRAM          "+str(board.info['variables_psram'])+" // Number of Javascript variables in RAM for boards with additional RAM (like ESP32 WROVER)");
    
    
    

    last not least in main.c

      if(esp_get_free_heap_size() > 0x300000) jsVarsSize = JSVAR_CACHE_SIZE_PSRAM;  // looks like 4MB SPI_RAM is enabled for heap, pretty sure there is a better way, but for now ....
      else jsVarsSize = JSVAR_CACHE_SIZE;   // number of variables for boards without additional SPI RAM
      jsvInit();     // Initialize the variables
    
    
About

Avatar for JumJum @JumJum started