From 341ef5e8b2aa7db3eeadbcea2991d3d73ac9106e Mon Sep 17 00:00:00 2001 From: zhanghu Date: Wed, 16 Oct 2019 16:30:42 +0800 Subject: [PATCH] add heap_caps_get_size_free --- components/heap/heap_caps.c | 7 +++++++ components/heap/include/esp_heap_caps.h | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/components/heap/heap_caps.c b/components/heap/heap_caps.c index 9c7d91a2e..12b8513b9 100644 --- a/components/heap/heap_caps.c +++ b/components/heap/heap_caps.c @@ -450,3 +450,10 @@ void heap_caps_dump_all(void) { heap_caps_dump(MALLOC_CAP_INVALID); } + +size_t heap_caps_get_allocated_size( void *ptr ) +{ + heap_t *heap = find_containing_heap(ptr); + size_t size = multi_heap_get_allocated_size(heap->heap, ptr); + return size; +} diff --git a/components/heap/include/esp_heap_caps.h b/components/heap/include/esp_heap_caps.h index 3b7252288..b4620bb44 100644 --- a/components/heap/include/esp_heap_caps.h +++ b/components/heap/include/esp_heap_caps.h @@ -310,6 +310,19 @@ void heap_caps_dump(uint32_t caps); */ void heap_caps_dump_all(void); +/** + * @brief Return the size that a particular pointer was allocated with. + * + * @param ptr Pointer to currently allocated heap memory. Must be a pointer value previously + * returned by heap_caps_malloc,malloc,calloc, etc. and not yet freed. + * + * @note The app will crash with an assertion failure if the pointer is not valid. + * + * @return Size of the memory allocated at this block. + * + */ +size_t heap_caps_get_allocated_size( void *ptr ); + #ifdef __cplusplus } #endif