The life cycle of data arriving via MQTT_EVENT_DATA

Troy Mitchell
Posts: 13
Joined: Fri Aug 16, 2024 1:55 am

The life cycle of data arriving via MQTT_EVENT_DATA

Postby Troy Mitchell » Fri Aug 16, 2024 2:00 am

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.

ESP_Sprite
Posts: 9577
Joined: Thu Nov 26, 2015 4:08 am

Re: The life cycle of data arriving via MQTT_EVENT_DATA

Postby ESP_Sprite » 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.

Troy Mitchell
Posts: 13
Joined: Fri Aug 16, 2024 1:55 am

Re: The life cycle of data arriving via MQTT_EVENT_DATA

Postby Troy Mitchell » Fri Aug 16, 2024 10:03 am

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

ESP_Sprite
Posts: 9577
Joined: Thu Nov 26, 2015 4:08 am

Re: The life cycle of data arriving via MQTT_EVENT_DATA

Postby ESP_Sprite » 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.

Troy Mitchell
Posts: 13
Joined: Fri Aug 16, 2024 1:55 am

Re: The life cycle of data arriving via MQTT_EVENT_DATA

Postby Troy Mitchell » Sat Aug 17, 2024 6:07 am

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.

Who is online

Users browsing this forum: No registered users and 276 guests