1
0
mirror of https://github.com/esphome/esphome.git synced 2025-04-13 14:20:29 +01:00

[helpers] Allow RAMAllocator to be told the size of the object manually (#8356)

This commit is contained in:
Jesse Hills 2025-03-03 20:11:19 +13:00 committed by GitHub
parent 2af5fd5210
commit 0350eafc1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,11 +3,11 @@
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
#include <functional> #include <functional>
#include <limits>
#include <memory> #include <memory>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <vector> #include <vector>
#include <limits>
#include "esphome/core/optional.h" #include "esphome/core/optional.h"
@ -700,8 +700,10 @@ template<class T> class RAMAllocator {
} }
template<class U> constexpr RAMAllocator(const RAMAllocator<U> &other) : flags_{other.flags_} {} template<class U> constexpr RAMAllocator(const RAMAllocator<U> &other) : flags_{other.flags_} {}
T *allocate(size_t n) { T *allocate(size_t n) { return this->allocate(n, sizeof(T)); }
size_t size = n * sizeof(T);
T *allocate(size_t n, size_t manual_size) {
size_t size = n * manual_size;
T *ptr = nullptr; T *ptr = nullptr;
#ifdef USE_ESP32 #ifdef USE_ESP32
if (this->flags_ & Flags::ALLOC_EXTERNAL) { if (this->flags_ & Flags::ALLOC_EXTERNAL) {