AN2345 Freescale Semiconductor / Motorola, AN2345 Datasheet - Page 19

no-image

AN2345

Manufacturer Part Number
AN2345
Description
Real-Time Memory Manager for StarCore DSPs
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
4.5 Freeing Memory
4.6 Eliminating Heaps
4.7 Querying Heaps
// Allocate a Memory Block from Heap2
apucBlockPtrArray2[0] = (unsigned char *) VSMMMemAlloc(
// Verify allocation was a success
if(ucErrCode != VSMM_NO_ERR)
{
}
Upon successful completion of this call, apucBlockPtrArray[0] points to the start of a memory block of
size 784 bytes, of which 776 bytes is available for use by the application with the remaining 8 bytes used
by VSMM to manage this block. Figure 5 on page 8 illustrates a memory block allocation.
Freeing a memory block is handled much like the standard C free call. We call the VSMMMemFree
routine, passing it the pointer to the memory block to be freed.
if((ucErrCode = VSMMMemFree(apucBlockPtrArray2[0])) != VSMM_NO_ERR)
{
}
As with memory allocation, it is good practice to verify that the operation succeeded.
Heaps can be eliminated at run-time as long as all their memory blocks are freed. To eliminate a heap, we
call the VSMMMemDestroy routine, passing it a pointer to the MCB of the heap to be removed.
Remember to verify that the operation succeeded.
if((ucErrCode = VSMMMemDestroy(pstHeap2Ptr)) != VSMM_NO_ERR)
{
}
To obtain information on a heap, we call the VSMMMemQuery routine and pass it a pointer to the MCB
of a specified heap and a pointer to a data control block. VSMMMemQuery returns a success status so
there is no need to perform a separate verification.
ucErrCode = VSMMMemQuery(pstHeap2Ptr, &stPartQ);
printf("ERROR %d -- Unable to Allocate Block from Heap2\n",
asm(" debug");
printf("ERROR %d -- Unable to Free Memory Block \n",ucErrCode);
asm(" debug");
printf("ERROR %d -- Unable to Destroy Heap 2\n",ucErrCode);
asm(" debug");
Freescale Semiconductor, Inc.
For More Information On This Product,
ucErrCode);
Go to: www.freescale.com
pstHeap2Ptr,
&ucErrCode);
Building Your Application with VSMM
19

Related parts for AN2345