From 0350eafc1e15f30763fc9170eba960232851b919 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 3 Mar 2025 20:11:19 +1300 Subject: [PATCH] [helpers] Allow RAMAllocator to be told the size of the object manually (#8356) --- esphome/core/helpers.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 82b0fe07f8..3f371cd829 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -3,11 +3,11 @@ #include #include #include +#include #include #include #include #include -#include #include "esphome/core/optional.h" @@ -700,8 +700,10 @@ template class RAMAllocator { } template constexpr RAMAllocator(const RAMAllocator &other) : flags_{other.flags_} {} - T *allocate(size_t n) { - size_t size = n * sizeof(T); + T *allocate(size_t n) { return this->allocate(n, sizeof(T)); } + + T *allocate(size_t n, size_t manual_size) { + size_t size = n * manual_size; T *ptr = nullptr; #ifdef USE_ESP32 if (this->flags_ & Flags::ALLOC_EXTERNAL) {