Skip to content

py/modgc: Add gc.add_heap() function for runtime heap expansion.#41

Draft
andrewleech wants to merge 1 commit intomasterfrom
pr/gc-add-heap
Draft

py/modgc: Add gc.add_heap() function for runtime heap expansion.#41
andrewleech wants to merge 1 commit intomasterfrom
pr/gc-add-heap

Conversation

@andrewleech
Copy link
Copy Markdown
Owner

Summary

Adds gc.add_heap(nbytes) which allocates a new heap segment from the system allocator and registers it with the split-heap GC. Useful on hosted ports where the working set can grow at runtime beyond the initial heap. Available when MICROPY_GC_SPLIT_HEAP_ADD is enabled (off by default).

Testing

Unix port with MICROPY_GC_SPLIT_HEAP=1 and MICROPY_GC_SPLIT_HEAP_ADD=1; verified additional segments are usable and that allocation past the initial heap succeeds.

Add a Python-level gc.add_heap(nbytes) that allocates a new heap segment
from the system allocator and registers it with the split-heap GC.
Available when MICROPY_GC_SPLIT_HEAP_ADD is enabled (off by default).
Useful on hosted ports where the working set can grow at runtime beyond
the initial heap allocation.

Returns the new total heap size; raises ValueError for sizes below the
minimum (4096 bytes) and MemoryError if the system allocation fails.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants