Skip to main content
Du1
Associate III
March 3, 2019
Solved

CanvasWidgetRenderer setup buffer

  • March 3, 2019
  • 2 replies
  • 1227 views

I read the 4.10.0 User Manual on CanvasWidgetRenderer.

I was unsure what it means by "CanvasWidget will not allocate memory dynamically, but will use memory from the buffer kept in CanvasWidget -Renderer."

I see the commented line in main.cpp:

//static uint8_t canvasBuffer[CANVAS_BUFFER_SIZE];
 //CanvasWidgetRenderer::setupBuffer(canvasBuffer, CANVAS_BUFFER_SIZE);

When I create screens with lineprogressbar the generated files all have :

static const uint16_t CANVAS_BUFFER_SIZE = 4800;
uint8_t canvasBuffer[CANVAS_BUFFER_SIZE];
 
CanvasWidgetRenderer::setupBuffer(canvasBuffer, CANVAS_BUFFER_SIZE);

Is it better to have one function (CanvasWidgetRenderer::setupBuffer(canvasBuffer, CANVAS_BUFFER_SIZE);) called in main.cpp or have multiple screen call (CanvasWidgetRenderer::setupBuffer(canvasBuffer, CANVAS_BUFFER_SIZE);) ?

The application is running fine with multiple calls, but I was just afraid this will create memory problem if the buffer isn't returned during teardown.

Thanks for the help!

This topic has been closed for replies.
Best answer by Martin KJELDSEN

Hi @Du​,

If you want different buffer sizes for individual screens its fine to do it in each screen. Only one screen (View+Presenter) can be active at any point in time. A new screen will get placement newed into the memory of the old one (statically allocated for worst case pair).

But it's also fine to just define one buffer size for all if that seems appropriate for your application.

Best regards,

Martin

2 replies

Martin KJELDSEN
Martin KJELDSENBest answer
Principal III
March 4, 2019

Hi @Du​,

If you want different buffer sizes for individual screens its fine to do it in each screen. Only one screen (View+Presenter) can be active at any point in time. A new screen will get placement newed into the memory of the old one (statically allocated for worst case pair).

But it's also fine to just define one buffer size for all if that seems appropriate for your application.

Best regards,

Martin

Du1
Du1Author
Associate III
March 4, 2019

Thanks for detailed explanation @Martin KJELDSEN​ !

Martin KJELDSEN
Principal III
March 4, 2019

You're welcome!