Dynamic memory allocation
Posted: Tue Jul 30, 2019 10:52 am
hello,
How to use dynamic memory allocation with Erika 3 on TriCore, I'am using Infineon Tricore AURIX build with RT-Druid.
I was trying for almost a week to use malloc, but it's seems that the memory allocation is not happening.
Am I missing something or what, did I need to add something to the oil file.
I'am really struggling with this guys and am running out of time.
I will explain to you what I'am working on, so I created 4 tasks:
-Sender1, Sender2, Sender3
-TaskLogger
The Senders tasks they want to send message to the TaskLogger, where the TaskLogger will display the message on the terminal so I created a chained list contain all the messages when the task logger will read the messages from the list and display them on the terminal.
This is the function responsible of the insertion into the list.
static void printf_t(List *list, char *pmessage, int sizemsg)
{
/*Creating the new t_logger_msg*/
t_logger_msg *newmsg = (t_logger_msg *) malloc(sizeof(t_logger_msg));
newmsg->pmessage = (char *) malloc((sizemsg+1) * sizeof(char));
newmsg->size = (int) malloc(sizeof(int));
strcpy(newmsg->pmessage, pmessage);
newmsg->size = sizemsg;
newmsg->next = NULL;
if (list->First != NULL) /* if the list is not empty */
{
t_logger_msg *ActuelMsg = list->Last;
ActuelMsg->next = newmsg;
list->Last = newmsg;
}
else /*if the list is empty*/
{
list->First = newmsg;
list->Last = newmsg;
}
}
And those are my structures:
/************************************************************************************************
*
* Structure
*
**********************************************************************************************/
typedef struct t_logger_msg t_logger_msg;
struct t_logger_msg
{
char * pmessage;
int size;
t_logger_msg* next;
};
/**************************************************************************************************************/
/*Another structure to control the entire linked list.*/
typedef struct List List;
struct List
{
t_logger_msg *First;
t_logger_msg *Last;
};
How to use dynamic memory allocation with Erika 3 on TriCore, I'am using Infineon Tricore AURIX build with RT-Druid.
I was trying for almost a week to use malloc, but it's seems that the memory allocation is not happening.
Am I missing something or what, did I need to add something to the oil file.
I'am really struggling with this guys and am running out of time.
I will explain to you what I'am working on, so I created 4 tasks:
-Sender1, Sender2, Sender3
-TaskLogger
The Senders tasks they want to send message to the TaskLogger, where the TaskLogger will display the message on the terminal so I created a chained list contain all the messages when the task logger will read the messages from the list and display them on the terminal.
This is the function responsible of the insertion into the list.
static void printf_t(List *list, char *pmessage, int sizemsg)
{
/*Creating the new t_logger_msg*/
t_logger_msg *newmsg = (t_logger_msg *) malloc(sizeof(t_logger_msg));
newmsg->pmessage = (char *) malloc((sizemsg+1) * sizeof(char));
newmsg->size = (int) malloc(sizeof(int));
strcpy(newmsg->pmessage, pmessage);
newmsg->size = sizemsg;
newmsg->next = NULL;
if (list->First != NULL) /* if the list is not empty */
{
t_logger_msg *ActuelMsg = list->Last;
ActuelMsg->next = newmsg;
list->Last = newmsg;
}
else /*if the list is empty*/
{
list->First = newmsg;
list->Last = newmsg;
}
}
And those are my structures:
/************************************************************************************************
*
* Structure
*
**********************************************************************************************/
typedef struct t_logger_msg t_logger_msg;
struct t_logger_msg
{
char * pmessage;
int size;
t_logger_msg* next;
};
/**************************************************************************************************************/
/*Another structure to control the entire linked list.*/
typedef struct List List;
struct List
{
t_logger_msg *First;
t_logger_msg *Last;
};