set_data_destroy_function

3

set_data_destroy_function

set function used to deallocate message data

    #include <cds/msg_queue.h>

    typedef void (*destroy_function_f)(void *);

      void set_data_destroy_function
      mq_message_t *msg
      destroy_function_f func

## Description

Set destroy function for message data. This function is called from `free_message` and is primarily used for deallocation of complex data structures or their content. It can be used on all types of messages (allocated using `create_message` or `create_message_ex` or initialized using `init_message_ex`).

### Usage with create_message_ex

    str_t *s;
    mq_message_t *msg = create_message_ex(sizeof(str_t));
    set_data_destroy_function((destroy_function_f)str_free_content);
    s = (str_t*)get_message_data(msg);
    str_dup_zt(s, "something happened");

### Usage with create_message

    str_t *s = cds_malloc(sizeof(str_t));
    mq_message_t *msg = create_message(s, sizeof(str_t));
    set_data_destroy_function((destroy_function_f)str_free);
    str_dup_zt(s, "something happened");

## See Also

create_message, create_message_ex, init_message_ex