Page 1 of 1
The life cycle of data arriving via MQTT_EVENT_DATA
Posted: Fri Aug 16, 2024 2:00 am
by Troy Mitchell
I got a message through event handle and I wanna send it through queue.
I know the queue will copy memory in FreeRTOS but the msg.data is a pointer so the memory that the pointer points will not be copied.
I wanna know what time the pointer will be free ? Should I copy the memory that the pointer points manually and free it after queue send.
Re: The life cycle of data arriving via MQTT_EVENT_DATA
Posted: Fri Aug 16, 2024 3:41 am
by ESP_Sprite
It won't be, not by FreeRTOS that is. If you push a pointer into a queue, FreeRTOS will just handle it as it would handle any opaque data, it doesn't know it's a pointer. You would normally free it after you receive it and are done with it.
Re: The life cycle of data arriving via MQTT_EVENT_DATA
Posted: Fri Aug 16, 2024 10:03 am
by Troy Mitchell
ESP_Sprite wrote: ↑Fri Aug 16, 2024 3:41 am
It won't be, not by FreeRTOS that is. If you push a pointer into a queue, FreeRTOS will just handle it as it would handle any opaque data, it doesn't know it's a pointer. You would normally free it after you receive it and are done with it.
What I mean is, the MQTT message I get through the event function (from MQTT), its data is a pointer, I send this message through the queue, then the data memory will not be copied, do I need to copy this memory to avoid it being released by the MQTT task? My question is about the life cycle of data in MQTT messages, not freertos
Re: The life cycle of data arriving via MQTT_EVENT_DATA
Posted: Sat Aug 17, 2024 5:45 am
by ESP_Sprite
Ah, gotcha. Generally you cannot assume the lifetime of any data passed into a callback exists past the duration of a callback; the documentation will explicitly mention it if it does persist longer.
Re: The life cycle of data arriving via MQTT_EVENT_DATA
Posted: Sat Aug 17, 2024 6:07 am
by Troy Mitchell
ESP_Sprite wrote: ↑Sat Aug 17, 2024 5:45 am
Ah, gotcha. Generally you cannot assume the lifetime of any data passed into a callback exists past the duration of a callback; the documentation will explicitly mention it if it does persist longer.
Got it! Thanks for ur response.
BEST REGARD.