Event management best practices

sigma_shig
Posts: 6
Joined: Sun Apr 23, 2023 10:19 am

Event management best practices

Postby sigma_shig » Thu Apr 27, 2023 4:44 am

How do you manage events? Let's review example:
On the Publisher side

Code: Select all

{
  {
    void* buffer = malloc(10);
    memcpy(buffer, "Hello", 0, 1024);
    res = esp_event_post(SIGMA_EVENT,
                         SIGMA_HELLO_EVENT_ID,
                         buffer,
                         0,
                         portMAX_DELAY);
  }
And we have several event handlers on Subscriber side

Code: Select all

res = esp_event_handler_instance_register(SIGMA_EVENT,
                                            SIGMA_HELLO_EVENT_ID,
                                            myEventHandler1,
                                            args,
                                            instance);

res = esp_event_handler_instance_register(SIGMA_EVENT,
                                            SIGMA_HELLO_EVENT_ID,
                                            myEventHandler2,
                                            args,
                                            instance);

How can I detect a moment, when I can free(buffer)? And should it be run on Publisher or Subscriber? Are there some best practices or tricks?

Who is online

Users browsing this forum: No registered users and 94 guests