mirror of
https://github.com/esphome/esphome.git
synced 2026-02-15 14:07:35 -07:00
RAMAllocator is stateless when using default flags — it's just a dispatch wrapper over heap_caps_malloc/realloc/free. There's no need to store it as a class member. Use stack-local instances at each call site instead, matching the pattern used in audio_transfer_buffer and ring_buffer. Co-Authored-By: J. Nick Koston <nick@koston.org>
25 lines
571 B
C++
25 lines
571 B
C++
#include "buffer_impl.h"
|
|
|
|
namespace esphome::camera {
|
|
|
|
BufferImpl::BufferImpl(size_t size) {
|
|
RAMAllocator<uint8_t> allocator;
|
|
this->data_ = allocator.allocate(size);
|
|
this->size_ = size;
|
|
}
|
|
|
|
BufferImpl::BufferImpl(CameraImageSpec *spec) {
|
|
RAMAllocator<uint8_t> allocator;
|
|
this->data_ = allocator.allocate(spec->bytes_per_image());
|
|
this->size_ = spec->bytes_per_image();
|
|
}
|
|
|
|
BufferImpl::~BufferImpl() {
|
|
if (this->data_ != nullptr) {
|
|
RAMAllocator<uint8_t> allocator;
|
|
allocator.deallocate(this->data_, this->size_);
|
|
}
|
|
}
|
|
|
|
} // namespace esphome::camera
|