This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DSP/BIOS MEM_alloc() function

Does anyone know the implementation of the DSP/BIOS MEM_alloc()-function since DSP/BIOS version 5.20 or greater. We need to print a list of the complete allocated memory in a memory segment. Our goal is to understand the allocation mechanism, to find memory leaks and to optimize the allocation process.

We have found a small pdf in the TexasInstruments Wiki but this pdf doesn't show the real implementation. We also found the MEM_Header structure which shows the linked list of the allocation function. But actually we are not able to walk through the list to find each allocated memory space.

Maybe someone has an idea of the implementation of the memory allocation. Please let me know!

Best regards.

  • Afaik  the MEM manager keeps a linked list of free blocks for each segment, I don't  know if there is an equivalent list of used blocks.

    We use the following code to walk through this list to find the maximum address allocated in a segment.

    hope this helps

    // getUsedTill evaluates the highest address allocated.
    // parameter pUsedTill is updated with the result
    // This function looks for the last free memory block in the segment segId and returns
    // the start address - 1
    void getUsedTill(Int segId, Ptr* pUsedTill)
    {
        MEM_Header *pMyHeader = &MEM_freelist[ segId ];
        MEM_Header *allocMem = pMyHeader->next;
        MEM_Header *maxAddr = allocMem;
       
        while( allocMem->next )
       
        {
            allocMem =  allocMem->next;  
            if (allocMem>maxAddr) maxAddr=allocMem; 
        };

        *pUsedTill = (void*) ((unsigned int)maxAddr -1);
    }

     

  • Hello Mr Bauer,

    Thank you very much for the reply.

    We have a similar function to walk through the free-list. TI uses a mechanism similar to the description in the Kerninghan/Ritchie. My problem in this issue was the position of the MEM_freelist[ segId ] . I have found the start point at the end of the heap. But until now I don't know if this is really the free-list. Thank you because of this issue.

    The problem with the used blocks list is still open. Actually we doesn't know if TI marks a used memory block in any way. (Because they do it in later versions) We need to run through the free list and through the allocated list to understand the runtime of malloc and free in a better way. But it seems to me that it is better to write my own malloc/free function :-)

  • Just to complete the info:

    In later versions of BIOS MEM_freelist has been renamed to MEM_D_freelist.