-
An ESP8266, programmed using microPython 1.22.1 via Thonny 4.1.4, has two sensors attached to it and the measured values are reported via JSON-encoded MQTT messages. A message with the values from one sensor is build in an io.BytesIO() buffer. The basic flow is currently:
Buffer pld is thus used once, than deleted and recreated. That is the only way I found so far to clear the content of pld, that is the value of method pld.getvalue() becomes b''. I wonder if it is possible to clear buffer pld without recreating it, as object creation (and thus deletion and thus garbage collection) can be relatively costly on such a small processor. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
I'd use a preallocated bytearray and memoryview, not BytesIO |
Beta Was this translation helpful? Give feedback.
As a static pre-allocated bytearray seems to be the way to go, I'll try to use class StaticBuffer, shown below, as a replacement of class io.BytesIO. Class StaticBuffer is (for now) modeled after class io.BytesIO.