Berry extend max bytes size to 512Kb when PSRAM is available

This commit is contained in:
Stephan Hadinger 2022-08-30 18:11:04 +02:00
parent 286b0ca916
commit cb4a5ed736
5 changed files with 15 additions and 2 deletions

View File

@ -41,6 +41,14 @@
**/
#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
* Use precompiled objects to avoid creating these objects at
* runtime. Enable this macro can greatly optimize RAM usage.

View File

@ -18,7 +18,6 @@
#include <ctype.h>
#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_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)
{
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;
attr->bufptr = (uint8_t*) be_realloc(vm, attr->bufptr, oldsize, size); /* malloc */
attr->size = size;

View File

@ -477,6 +477,7 @@ BERRY_API bvm* be_vm_new(void)
be_gc_setpause(vm, 1);
be_loadlibs(vm);
vm->compopt = 0;
vm->bytesmaxsize = BE_BYTES_MAX_SIZE;
vm->obshook = NULL;
vm->ctypefunc = NULL;
#if BE_USE_PERF_COUNTERS

View File

@ -105,6 +105,7 @@ struct bvm {
struct bgc gc;
bctypefunc ctypefunc; /* handler to ctype_func */
bbyte compopt; /* compilation options */
uint32_t bytesmaxsize; /* max allowed size for bytes() object, default 32kb but can be increased */
bobshook obshook;
bmicrosfnct microsfnct; /* fucntion to get time as a microsecond resolution */
#if BE_USE_PERF_COUNTERS

View File

@ -316,6 +316,10 @@ void BerryInit(void) {
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);
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
// Set the GC threshold to 3584 bytes to avoid the first useless GC