py: Add option to reduce GC stack integer size to save RAM.
A new option MICROPY_GC_STACK_ENTRY_TYPE is added to select a custom type instead of size_t for the gc_stack array items. This can be beneficial for small devices, especially those that are low on memory anyway. If a device has 1MB or less of heap (and 16-byte GC blocks) then this type can be uint16_t, saving 128 bytes of RAM.
This commit is contained in:
parent
62b4bebf64
commit
31cf528c75
|
@ -106,6 +106,15 @@
|
||||||
#define MICROPY_ALLOC_GC_STACK_SIZE (64)
|
#define MICROPY_ALLOC_GC_STACK_SIZE (64)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// The C-type to use for entries in the GC stack. By default it allows the
|
||||||
|
// heap to be as large as the address space, but the bit-width of this type can
|
||||||
|
// be reduced to save memory when the heap is small enough. The type must be
|
||||||
|
// big enough to index all blocks in the heap, which is set by
|
||||||
|
// heap-size-in-bytes / MICROPY_BYTES_PER_GC_BLOCK.
|
||||||
|
#ifndef MICROPY_GC_STACK_ENTRY_TYPE
|
||||||
|
#define MICROPY_GC_STACK_ENTRY_TYPE size_t
|
||||||
|
#endif
|
||||||
|
|
||||||
// Be conservative and always clear to zero newly (re)allocated memory in the GC.
|
// Be conservative and always clear to zero newly (re)allocated memory in the GC.
|
||||||
// This helps eliminate stray pointers that hold on to memory that's no longer
|
// This helps eliminate stray pointers that hold on to memory that's no longer
|
||||||
// used. It decreases performance due to unnecessary memory clearing.
|
// used. It decreases performance due to unnecessary memory clearing.
|
||||||
|
|
|
@ -77,7 +77,7 @@ typedef struct _mp_state_mem_t {
|
||||||
byte *gc_pool_end;
|
byte *gc_pool_end;
|
||||||
|
|
||||||
int gc_stack_overflow;
|
int gc_stack_overflow;
|
||||||
size_t gc_stack[MICROPY_ALLOC_GC_STACK_SIZE];
|
MICROPY_GC_STACK_ENTRY_TYPE gc_stack[MICROPY_ALLOC_GC_STACK_SIZE];
|
||||||
uint16_t gc_lock_depth;
|
uint16_t gc_lock_depth;
|
||||||
|
|
||||||
// This variable controls auto garbage collection. If set to 0 then the
|
// This variable controls auto garbage collection. If set to 0 then the
|
||||||
|
|
Loading…
Reference in New Issue