10000 add support to split heap in multiple ranges · Issue #3758 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content
add support to split heap in multiple ranges #3758
Closed
@adritium

Description

@adritium

In current gc initialization, it is only possible to provide one range for the heap.

micropython/py/gc.c

Lines 108 to 120 in 12a3fcc

void gc_init(void *start, void *end) {
// align end pointer on block boundary
end = (void*)((uintptr_t)end & (~(BYTES_PER_BLOCK - 1)));
DEBUG_printf("Initializing GC heap: %p..%p = " UINT_FMT " bytes\n", start, end, (byte*)end - (byte*)start);
// calculate parameters for GC (T=total, A=alloc table, F=finaliser table, P=pool; all in bytes):
// T = A + F + P
// F = A * BLOCKS_PER_ATB / BLOCKS_PER_FTB
// P = A * BLOCKS_PER_ATB * BYTES_PER_BLOCK
// => T = A * (1 + BLOCKS_PER_ATB / BLOCKS_PER_FTB + BLOCKS_PER_ATB * BYTES_PER_BLOCK)
size_t total_byte_len = (byte*)end - (byte*)start;
#if MICROPY_ENABLE_FINALISER
MP_STATE_MEM(gc_alloc_table_byte_len) = total_byte_len * BITS_PER_BYTE / (BITS_PER_BYTE + BITS_PER_BYTE * BLOCKS_PER_ATB / BLOCKS_PER_FTB + BITS_PER_BYTE * BLOCKS_PER_ATB * BYTES_PER_BLOCK);

However, all the RAM available on a micro-controller might not be in a contiguous range because there might be different types of RAM: SRAM, SDRAM, SPI-RAM, peripheral-dedicated RAM etc.

In my particular case, there is 4K of RAM that is used by a certain peripheral but only if it's enabled but otherwise, it's free for general-purpose use.
Unfortunately, 4K is too small for (most of) my uses as a heap by itself but if I could append it to my main heap, I wouldn't be letting 4K of RAM go to waste.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0