Most of the examples I have seen are using numbers like int.
Thanks in advance
Thank you for the response. Will check ringbuffer. Saw the unit test and will check the code from there.A queue actually is made for items with a defined length; if you throw in strings it'll waste a bunch of memory. Maybe you want to look at the ringbuffer implementation (in components/freertos/ringbuf.c and components/freertos/include/freertos/ringbuf.h) instead? Unfortunately, I also do not have an example for that (although, if I recall correctly, there should be an unit test for that thing somewhere.)
Sounds good. Do you have any code samples for it I can check?I have used queues to pass strings around in some of my projects. What I do is allocate storage for the string (so that it is not on stack) and then add a pointer to the string into the queue. The reader of the queue then sees a new entry which is a pointer to the string, works with the string and then deletes the allocated storage. The queue elements then become fixed size ... which is of course the size of a memory pointer. The un-written contract then becomes that the storage pointed to by the item on the queue has to be deleted/freed by the consumer.
Code: Select all
sizeof(char *)
Code: Select all
char *myData = "helloWorld";
Code: Select all
char *myItem = malloc(strlen(myData)+1);
strcpy(myItem, myData);
Code: Select all
xQueueSendToBack(myQueue, &myItem, portMAX_DELAY);
Code: Select all
char *myReceivedItem;
xQueueReceive(myQueue, &myReceivedItem, portMAX_DELAY);
// Do something with received string and then delete it ...
free(myReceivedItem);
Users browsing this forum: No registered users and 1 guest