File tree Expand file tree Collapse file tree 4 files changed +28
-1
lines changed Expand file tree Collapse file tree 4 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -464,8 +464,22 @@ MP_NOINLINE int main_(int argc, char **argv) {
464
464
pre_process_options (argc , argv );
465
465
466
466
#if MICROPY_ENABLE_GC
467
+ #if !MICROPY_GC_MULTIHEAP
467
468
char * heap = malloc (heap_size );
468
469
gc_init (heap , heap + heap_size );
470
+ #else
471
+ assert (MICROPY_GC_N_HEAPS > 0 );
472
+ char * heaps [MICROPY_GC_N_HEAPS ];
473
+ long multi_heap_size = heap_size / MICROPY_GC_N_HEAPS ;
474
+ for (size_t i = 0 ; i < MICROPY_GC_N_HEAPS ; i ++ ) {
475
+ heaps [i ] = malloc (multi_heap_size );
476
+ if (i == 0 ) {
477
+ gc_init (heaps [i ], heaps [i ] + multi_heap_size );
478
+ } else {
479
+ gc_add (heaps [i ], heaps [i ] + multi_heap_size );
480
+ }
481
+ }
482
+ #endif
469
483
#endif
470
484
471
485
#if MICROPY_ENABLE_PYSTACK
@@ -716,7 +730,13 @@ MP_NOINLINE int main_(int argc, char **argv) {
716
730
#if MICROPY_ENABLE_GC && !defined(NDEBUG )
717
731
// We don't really need to free memory since we are about to exit the
718
732
// process, but doing so helps to find memory leaks.
733
+ #if !MICROPY_GC_MULTIHEAP
719
734
free (heap );
735
+ #else
736
+ for (size_t i = 0 ; i < MICROPY_GC_N_HEAPS ; i ++ ) {
737
+ free (heaps [i ]);
738
+ }
739
+ #endif
720
740
#endif
721
741
722
742
// printf("total bytes = %d\n", m_get_total_bytes_allocated());
Original file line number Diff line number Diff line change 120
120
#define MICROPY_EMIT_ARM (1)
121
121
#endif
122
122
#define MICROPY_ENABLE_GC (1)
123
+ // Number of heaps to assign if MICROPY_GC_MULTIHEAP=1
124
+ #ifndef MICROPY_GC_N_HEAPS
125
+ #define MICROPY_GC_N_HEAPS (1)
126
+ #endif
123
127
#define MICROPY_MALLOC_USES_ALLOCATED_SIZE (1)
124
128
#define MICROPY_MEM_STATS (1)
125
129
#define MICROPY_DEBUG_PRINTERS (1)
Original file line number Diff line number Diff line change 56
56
#define MICROPY_PY_UCRYPTOLIB (1)
57
57
#define MICROPY_PY_UCRYPTOLIB_CTR (1)
58
58
#define MICROPY_PY_MICROPYTHON_HEAP_LOCKED (1)
59
- #define MICROPY_GC_MULTIHEAP (1)
59
+ #define MICROPY_GC_MULTIHEAP (1)
60
+ #define MICROPY_GC_N_HEAPS (4)
Original file line number Diff line number Diff line change 30
30
#include <stddef.h>
31
31
32
32
void gc_init (void * start , void * end );
33
+
34
+ // Used to add additional heaps when multiple heaps are enabled.
33
35
void gc_add (void * start , void * end );
34
36
35
37
// These lock/unlock functions can be nested.
You can’t perform that action at this time.
0 commit comments