malloc function used in iLLD code?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
E-John
Level 3
Level 3
10 replies posted First like given 25 sign-ins

Dear Sir,

Is it OK to use  malloc() function in iLLD code?

It is needed to free it to avoid memory leak,

besides that, is there any to note?Thanks.

 

0 Likes
1 Solution
Ken_Yeung
Moderator
Moderator
Moderator
10 replies posted 25 sign-ins 5 solutions authored

Hi John,

  iLLD is Infineon Low Level Driver.  It does not provide the implementation of memory management function (e.g. malloc). It is implemented by other software component.

  For your question, it depends on the design of memory management function. Therefore, user needs to refer to user manual of the memory management function. The user manual may have information on how to use those functions to allow memory issue. 

Ken

View solution in original post

3 Replies
Ken_Yeung
Moderator
Moderator
Moderator
10 replies posted 25 sign-ins 5 solutions authored

Hello John,

  Would you explain more about your concern? Besides, would you provide a use case of using malloc() function in ILLD code you want to discuss?

Ken

0 Likes

Hi Ken,

Because "malloc" only found once in this function, 

My use case is

Variable array is handled with inside my function. And malloc() is be used to allocate a variable memory,  free() is used to return the memory to heap before exiting function. 

Just want to know, after many times malloc and free, there is no memory leak to cause out of memory issue. Thanks.

 

Ifx_Fifo *Ifx_Fifo_create(Ifx_SizeT size, Ifx_SizeT elementSize)
{
    Ifx_Fifo *fifo = NULL_PTR;

    size = Ifx_AlignOn32(size);                 /* data transfer is optimised for 32 bit access */

    fifo = malloc(size + sizeof(Ifx_Fifo) + 8); /* +8 because of padding in case the pointer is not aligned on 64 */

    if (IFX_VALIDATE(IFX_VERBOSE_LEVEL_ERROR, (fifo != NULL_PTR)))
    {
        fifo = Ifx_Fifo_init(fifo, size, elementSize);
    }

    return fifo;
}

void Ifx_Fifo_destroy(Ifx_Fifo *fifo)
{
    free(fifo);
}

 

 

0 Likes
Ken_Yeung
Moderator
Moderator
Moderator
10 replies posted 25 sign-ins 5 solutions authored

Hi John,

  iLLD is Infineon Low Level Driver.  It does not provide the implementation of memory management function (e.g. malloc). It is implemented by other software component.

  For your question, it depends on the design of memory management function. Therefore, user needs to refer to user manual of the memory management function. The user manual may have information on how to use those functions to allow memory issue. 

Ken