Compare commits

..

1 Commits

Author SHA1 Message Date
J. Nick Koston
df3a36376d [camera, camera_encoder] Remove stored RAMAllocator member
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>
2026-02-14 15:32:11 -07:00
4 changed files with 14 additions and 9 deletions

View File

@@ -3,18 +3,22 @@
namespace esphome::camera {
BufferImpl::BufferImpl(size_t size) {
this->data_ = this->allocator_.allocate(size);
RAMAllocator<uint8_t> allocator;
this->data_ = allocator.allocate(size);
this->size_ = size;
}
BufferImpl::BufferImpl(CameraImageSpec *spec) {
this->data_ = this->allocator_.allocate(spec->bytes_per_image());
RAMAllocator<uint8_t> allocator;
this->data_ = allocator.allocate(spec->bytes_per_image());
this->size_ = spec->bytes_per_image();
}
BufferImpl::~BufferImpl() {
if (this->data_ != nullptr)
this->allocator_.deallocate(this->data_, this->size_);
if (this->data_ != nullptr) {
RAMAllocator<uint8_t> allocator;
allocator.deallocate(this->data_, this->size_);
}
}
} // namespace esphome::camera

View File

@@ -18,7 +18,6 @@ class BufferImpl : public Buffer {
~BufferImpl() override;
protected:
RAMAllocator<uint8_t> allocator_;
size_t size_{};
uint8_t *data_{};
};

View File

@@ -4,7 +4,8 @@ namespace esphome::camera_encoder {
bool EncoderBufferImpl::set_buffer_size(size_t size) {
if (size > this->capacity_) {
uint8_t *p = this->allocator_.reallocate(this->data_, size);
RAMAllocator<uint8_t> allocator;
uint8_t *p = allocator.reallocate(this->data_, size);
if (p == nullptr)
return false;
@@ -16,8 +17,10 @@ bool EncoderBufferImpl::set_buffer_size(size_t size) {
}
EncoderBufferImpl::~EncoderBufferImpl() {
if (this->data_ != nullptr)
this->allocator_.deallocate(this->data_, this->capacity_);
if (this->data_ != nullptr) {
RAMAllocator<uint8_t> allocator;
allocator.deallocate(this->data_, this->capacity_);
}
}
} // namespace esphome::camera_encoder

View File

@@ -16,7 +16,6 @@ class EncoderBufferImpl : public camera::EncoderBuffer {
~EncoderBufferImpl() override;
protected:
RAMAllocator<uint8_t> allocator_;
size_t capacity_{};
size_t size_{};
uint8_t *data_{};