Compare commits

...

1 Commits

Author SHA1 Message Date
J. Nick Koston
be5f4845eb [runtime_image] Remove stored RAMAllocator member
RAMAllocator with default flags is stateless — 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:34:11 -07:00
4 changed files with 9 additions and 7 deletions

View File

@@ -50,7 +50,8 @@ static void draw_callback(pngle_t *pngle, uint32_t x, uint32_t y, uint32_t w, ui
PngDecoder::PngDecoder(RuntimeImage *image) : ImageDecoder(image) {
{
pngle_t *pngle = this->allocator_.allocate(1, PNGLE_T_SIZE);
RAMAllocator<pngle_t> allocator;
pngle_t *pngle = allocator.allocate(1, PNGLE_T_SIZE);
if (!pngle) {
ESP_LOGE(TAG, "Failed to allocate memory for PNGLE engine!");
return;
@@ -64,7 +65,8 @@ PngDecoder::PngDecoder(RuntimeImage *image) : ImageDecoder(image) {
PngDecoder::~PngDecoder() {
if (this->pngle_) {
pngle_reset(this->pngle_);
this->allocator_.deallocate(this->pngle_, PNGLE_T_SIZE);
RAMAllocator<pngle_t> allocator;
allocator.deallocate(this->pngle_, PNGLE_T_SIZE);
}
}

View File

@@ -29,7 +29,6 @@ class PngDecoder : public ImageDecoder {
uint32_t get_pixels_decoded() const { return this->pixels_decoded_; }
protected:
RAMAllocator<pngle_t> allocator_;
pngle_t *pngle_{nullptr};
uint32_t pixels_decoded_{0};
};

View File

@@ -230,7 +230,8 @@ void RuntimeImage::release() {
void RuntimeImage::release_buffer_() {
if (this->buffer_) {
ESP_LOGV(TAG, "Releasing buffer of size %zu", this->get_buffer_size_(this->buffer_width_, this->buffer_height_));
this->allocator_.deallocate(this->buffer_, this->get_buffer_size_(this->buffer_width_, this->buffer_height_));
RAMAllocator<uint8_t> allocator;
allocator.deallocate(this->buffer_, this->get_buffer_size_(this->buffer_width_, this->buffer_height_));
this->buffer_ = nullptr;
this->data_start_ = nullptr;
this->width_ = 0;
@@ -254,11 +255,12 @@ size_t RuntimeImage::resize_buffer_(int width, int height) {
}
ESP_LOGD(TAG, "Allocating buffer: %dx%d, %zu bytes", width, height, new_size);
this->buffer_ = this->allocator_.allocate(new_size);
RAMAllocator<uint8_t> allocator;
this->buffer_ = allocator.allocate(new_size);
if (!this->buffer_) {
ESP_LOGE(TAG, "Failed to allocate %zu bytes. Largest free block: %zu", new_size,
this->allocator_.get_max_free_block_size());
allocator.get_max_free_block_size());
return 0;
}

View File

@@ -165,7 +165,6 @@ class RuntimeImage : public image::Image {
std::unique_ptr<ImageDecoder> create_decoder_();
// Memory management
RAMAllocator<uint8_t> allocator_{};
uint8_t *buffer_{nullptr};
// Decoder management