mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-08-18 16:05:05 +00:00
New Features - Added policy-based memory allocation APIs with capability flags and optional alignment: `memory_alloc_with_policy`, `memory_realloc_with_policy`, `memory_calloc_with_policy`, and `memory_free`. - Switched heap memory reporting to `memory_print_stats`. Bug Fixes - Improved allocation robustness with capability fallback behavior. - Added overflow-safe handling for aligned zero-initialized allocations. - Tightened const-correctness for generated device-tree device arrays. Tests - Added unit tests for default policy, alignment, zero-initialization, realloc preservation, freeing, and memory stats reporting.
30 lines
745 B
C++
30 lines
745 B
C++
#include <tactility/log.h>
|
|
#include <tactility/memory.h>
|
|
|
|
#ifdef ESP_PLATFORM
|
|
#include <esp_heap_caps.h>
|
|
#endif
|
|
|
|
constexpr auto* TAG = "memory";
|
|
|
|
extern "C" {
|
|
|
|
const struct MemoryPolicy MEMORY_POLICY_DEFAULT = {
|
|
.required = 0,
|
|
.desired = 0,
|
|
.alignment = 0,
|
|
};
|
|
|
|
void memory_print_stats() {
|
|
#ifdef ESP_PLATFORM
|
|
size_t heap_free = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
|
|
size_t heap_total = heap_caps_get_total_size(MALLOC_CAP_INTERNAL);
|
|
LOG_I(TAG, "Heap: %zu / %zu available", heap_free, heap_total);
|
|
size_t ext_free = heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
|
|
size_t ext_total = heap_caps_get_total_size(MALLOC_CAP_SPIRAM);
|
|
LOG_I(TAG, "External: %zu / %zu available", ext_free, ext_total);
|
|
#endif
|
|
}
|
|
|
|
}
|