mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-30 17:57:17 +00:00
Berry extend max bytes size to 512Kb when PSRAM is available
This commit is contained in:
parent
286b0ca916
commit
cb4a5ed736
@ -41,6 +41,14 @@
|
|||||||
**/
|
**/
|
||||||
#define BE_USE_SINGLE_FLOAT 1 // use `float` not `double`
|
#define BE_USE_SINGLE_FLOAT 1 // use `float` not `double`
|
||||||
|
|
||||||
|
/* Macro: BE_BYTES_MAX_SIZE
|
||||||
|
* Maximum size in bytes of a `bytes()` object.
|
||||||
|
* Putting too much pressure on the memory allocator can do
|
||||||
|
* harm, so we limit the maximum size.
|
||||||
|
* Default: 32kb
|
||||||
|
**/
|
||||||
|
#define BE_BYTES_MAX_SIZE (32*1024) /* 32 kb default value */
|
||||||
|
|
||||||
/* Macro: BE_USE_PRECOMPILED_OBJECT
|
/* Macro: BE_USE_PRECOMPILED_OBJECT
|
||||||
* Use precompiled objects to avoid creating these objects at
|
* Use precompiled objects to avoid creating these objects at
|
||||||
* runtime. Enable this macro can greatly optimize RAM usage.
|
* runtime. Enable this macro can greatly optimize RAM usage.
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#define BYTES_DEFAULT_SIZE 28 // default pre-reserved size for buffer (keep 4 bytes for len/size)
|
#define BYTES_DEFAULT_SIZE 28 // default pre-reserved size for buffer (keep 4 bytes for len/size)
|
||||||
#define BYTES_MAX_SIZE (32*1024) // max 32Kb
|
|
||||||
#define BYTES_OVERHEAD 4 // bytes overhead to be added when allocating (used to store len and size)
|
#define BYTES_OVERHEAD 4 // bytes overhead to be added when allocating (used to store len and size)
|
||||||
#define BYTES_HEADROOM 8 // keep a natural headroom of 8 bytes when resizing
|
#define BYTES_HEADROOM 8 // keep a natural headroom of 8 bytes when resizing
|
||||||
|
|
||||||
@ -506,7 +505,7 @@ void m_write_attributes(bvm *vm, int rel_idx, const buf_impl * attr)
|
|||||||
void bytes_realloc(bvm *vm, buf_impl * attr, int32_t size)
|
void bytes_realloc(bvm *vm, buf_impl * attr, int32_t size)
|
||||||
{
|
{
|
||||||
if (!attr->fixed && size < 4) { size = 4; }
|
if (!attr->fixed && size < 4) { size = 4; }
|
||||||
if (size > BYTES_MAX_SIZE) { size = BYTES_MAX_SIZE; }
|
if (size > vm->bytesmaxsize) { size = vm->bytesmaxsize; }
|
||||||
size_t oldsize = attr->bufptr ? attr->size : 0;
|
size_t oldsize = attr->bufptr ? attr->size : 0;
|
||||||
attr->bufptr = (uint8_t*) be_realloc(vm, attr->bufptr, oldsize, size); /* malloc */
|
attr->bufptr = (uint8_t*) be_realloc(vm, attr->bufptr, oldsize, size); /* malloc */
|
||||||
attr->size = size;
|
attr->size = size;
|
||||||
|
@ -477,6 +477,7 @@ BERRY_API bvm* be_vm_new(void)
|
|||||||
be_gc_setpause(vm, 1);
|
be_gc_setpause(vm, 1);
|
||||||
be_loadlibs(vm);
|
be_loadlibs(vm);
|
||||||
vm->compopt = 0;
|
vm->compopt = 0;
|
||||||
|
vm->bytesmaxsize = BE_BYTES_MAX_SIZE;
|
||||||
vm->obshook = NULL;
|
vm->obshook = NULL;
|
||||||
vm->ctypefunc = NULL;
|
vm->ctypefunc = NULL;
|
||||||
#if BE_USE_PERF_COUNTERS
|
#if BE_USE_PERF_COUNTERS
|
||||||
|
@ -105,6 +105,7 @@ struct bvm {
|
|||||||
struct bgc gc;
|
struct bgc gc;
|
||||||
bctypefunc ctypefunc; /* handler to ctype_func */
|
bctypefunc ctypefunc; /* handler to ctype_func */
|
||||||
bbyte compopt; /* compilation options */
|
bbyte compopt; /* compilation options */
|
||||||
|
uint32_t bytesmaxsize; /* max allowed size for bytes() object, default 32kb but can be increased */
|
||||||
bobshook obshook;
|
bobshook obshook;
|
||||||
bmicrosfnct microsfnct; /* fucntion to get time as a microsecond resolution */
|
bmicrosfnct microsfnct; /* fucntion to get time as a microsecond resolution */
|
||||||
#if BE_USE_PERF_COUNTERS
|
#if BE_USE_PERF_COUNTERS
|
||||||
|
@ -316,6 +316,10 @@ void BerryInit(void) {
|
|||||||
comp_set_strict(berry.vm); /* Enable strict mode in Berry compiler, equivalent of `import strict` */
|
comp_set_strict(berry.vm); /* Enable strict mode in Berry compiler, equivalent of `import strict` */
|
||||||
be_set_ctype_func_hanlder(berry.vm, be_call_ctype_func);
|
be_set_ctype_func_hanlder(berry.vm, be_call_ctype_func);
|
||||||
|
|
||||||
|
if (UsePSRAM()) { // if PSRAM is available, raise the max size to 512kb
|
||||||
|
berry.vm->bytesmaxsize = 512 * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
be_load_custom_libs(berry.vm); // load classes and modules
|
be_load_custom_libs(berry.vm); // load classes and modules
|
||||||
|
|
||||||
// Set the GC threshold to 3584 bytes to avoid the first useless GC
|
// Set the GC threshold to 3584 bytes to avoid the first useless GC
|
||||||
|
Loading…
x
Reference in New Issue
Block a user