]> granicus.if.org Git - esp-idf/commitdiff
Add api to get total heap size in bytes for given capability
authorKewal <kewal@espressif.com>
Mon, 21 Oct 2019 06:55:58 +0000 (14:55 +0800)
committerAngus Gratton <angus@espressif.com>
Mon, 21 Oct 2019 06:55:58 +0000 (14:55 +0800)
components/heap/heap_caps.c
components/heap/include/esp_heap_caps.h

index 9c7d91a2ee5e7e87549f9fd0ccc6fbcdf2e86242..2a9b12a514bd6a6d8ed5ab03b7d931055ed5d994 100644 (file)
@@ -329,6 +329,18 @@ IRAM_ATTR void *heap_caps_calloc( size_t n, size_t size, uint32_t caps)
     return result;
 }
 
+size_t heap_caps_get_total_size(uint32_t caps)
+{
+    size_t total_size = 0;
+    heap_t *heap;
+    SLIST_FOREACH(heap, &registered_heaps, next) {
+        if (heap_caps_match(heap, caps)) {
+            total_size += (heap->end - heap->start);
+        }
+    }
+    return total_size;
+}
+
 size_t heap_caps_get_free_size( uint32_t caps )
 {
     size_t ret = 0;
index 3b72522886ee59aafccdae528b31029d277a07aa..6df13cbf599c8c9b6088bcfe3ea143f22b628161 100644 (file)
@@ -101,6 +101,20 @@ void *heap_caps_realloc( void *ptr, size_t size, int caps);
  */
 void *heap_caps_calloc(size_t n, size_t size, uint32_t caps);
 
+/**
+ * @brief Get the total size of all the regions that have the given capabilities
+ *
+ * This function takes all regions capable of having the given capabilities allocated in them
+ * and adds up the total space they have.
+ *
+ * @param caps        Bitwise OR of MALLOC_CAP_* flags indicating the type
+ *                    of memory
+ *
+ * @return total size in bytes
+ */
+
+size_t heap_caps_get_total_size(uint32_t caps);
+
 /**
  * @brief Get the total free size of all the regions that have the given capabilities
  *