diff --git a/components/esp_matter/esp_matter_mem.cpp b/components/esp_matter/esp_matter_mem.cpp index 070e86708..c374e95f6 100644 --- a/components/esp_matter/esp_matter_mem.cpp +++ b/components/esp_matter/esp_matter_mem.cpp @@ -1,4 +1,4 @@ -// Copyright 2021 Espressif Systems (Shanghai) PTE LTD +// Copyright 2023 Espressif Systems (Shanghai) PTE LTD // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -29,6 +29,19 @@ IRAM_ATTR void *esp_matter_mem_calloc(size_t n, size_t size) #endif } +IRAM_ATTR void *esp_matter_mem_realloc(void *ptr, size_t size) +{ +#if CONFIG_ESP_MATTER_MEM_ALLOC_MODE_INTERNAL + return heap_caps_realloc(ptr, size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); +#elif CONFIG_ESP_MATTER_MEM_ALLOC_MODE_EXTERNAL + return heap_caps_realloc(ptr, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); +#elif CONFIG_ESP_MATTER_MEM_ALLOC_MODE_IRAM_8BIT + return heap_caps_realloc_prefer(ptr, size, 2, MALLOC_CAP_INTERNAL | MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); +#else + return realloc(ptr, size); +#endif +} + IRAM_ATTR void esp_matter_mem_free(void *ptr) { #if CONFIG_ESP_MATTER_MEM_ALLOC_MODE_DEFAULT diff --git a/components/esp_matter/esp_matter_mem.h b/components/esp_matter/esp_matter_mem.h index debbd6a96..4f084f8fc 100644 --- a/components/esp_matter/esp_matter_mem.h +++ b/components/esp_matter/esp_matter_mem.h @@ -1,4 +1,4 @@ -// Copyright 2021 Espressif Systems (Shanghai) PTE LTD +// Copyright 2023 Espressif Systems (Shanghai) PTE LTD // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,3 +24,9 @@ void *esp_matter_mem_calloc(size_t n, size_t size); * @param[in] ptr pointer to the memory to be freed. */ void esp_matter_mem_free(void *ptr); + +/** ESP Matter realloc + * @param[in] ptr Pointer to reallocate + * @param[in] size size to reallocate + */ +void *esp_matter_mem_realloc(void *ptr, size_t size);