Page 1 of 1

Event management best practices

Posted: Thu Apr 27, 2023 4:44 am
by sigma_shig
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?