Texas Instruments TMS320 User Manual page 191

Dsp/bios v5.40
Hide thumbs Also See for TMS320:
Table of Contents

Advertisement

Example 5-7. Memory Allocation (C5000 and C28x Platform
/*
======== memtest.c ========
*
This code allocates/frees memory from different memory segments.
*/
#include <std.h>
#include <log.h>
#include <mem.h>
#define NALLOCS 2
#define BUFSIZE 128
/* "trace" Log created by Configuration Tool */
extern LOG_Obj trace;
#ifdef -28-
extern Int IDATA;
#endif
#ifdef -55-
extern Int DATA;
#endif
static Void printmem(Int segid);
/*
*
======== main ========
*/
Void main()
{
Int i;
Ptr ram[NALLOCS];
LOG_printf(&trace, "before allocating ...");
/* print initial memory status */
printmem(IDATA);
LOG_printf(&trace, "allocating ...");
/* allocate some memory from each segment */
for (i = 0; i < NALLOCS; i++) {
ram[i] = MEM_alloc(IDATA, BUFSIZE, 0);
LOG_printf(&trace, "seg %d: ptr = 0x%x", IDATA, ram[i]);
}
LOG_printf(&trace, "after allocating ...");
/* print memory status */
printmem(IDATA);
/* free memory */
for (i = 0; i < NALLOCS; i++) {
MEM_free(IDATA, ram[i], BUFSIZE);
}
LOG_printf(&trace, "after freeing ...");
/* print memory status */
printmem(IDATA);
}
/*
*
======== printmem ========
*/
static Void printmem(Int segid)
{
MEM_Stat
statbuf;
MEM_stat(segid, &statbuf);
LOG_printf(&trace, "seg %d: O 0x%x", segid, statbuf.size);
LOG_printf(&trace, "\tU 0x%x\tA 0x%x", statbuf.used, stat-
buf.length);
}
Note:
Non-pointer type function arguments to LOG_printf need explicit type
casting to (Arg) as shown in the following code example:
LOG_printf(&trace, "Task %d Done", (Arg)id);
)
s
/* # of allocations from each segment */
/* size of allocations */
Memory and Low-level Functions
Memory Management
5-9

Advertisement

Table of Contents
loading

Table of Contents