/* Same for realloc() Note: keep the logic in here the same as in heap_caps_malloc_default (or merge the two as soon as this gets more complex...)  */
IRAM_ATTR void* heap_caps_realloc_default(void *ptr, size_t size)
/* Same for realloc() Note: keep the logic in here the same as in heap_caps_malloc_default (or merge the two as soon as this gets more complex...)  */
IRAM_ATTR void* heap_caps_realloc_default(void *ptr, size_t size)
{
    if (malloc_alwaysinternal_limit==MALLOC_DISABLE_EXTERNAL_ALLOCS) {
        return heap_caps_realloc( ptr, size, MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL );
    } else {
        void *r;
        if (size <= malloc_alwaysinternal_limit) {
            r=heap_caps_realloc( ptr, size, MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL );
        } else {
            r=heap_caps_realloc( ptr, size, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM );
        }
        if (r==NULL && size>0) {
            r=heap_caps_realloc( ptr, size, MALLOC_CAP_DEFAULT );
        }
        return r;
    }
}