EasyManua.ls Logo

Texas Instruments TMS320 - Page 191

Texas Instruments TMS320
288 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Memory Management
Memory and Low-level Functions 5-9
Example 5-7. Memory Allocation (C5000 and C28x Platforms)
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);
/* ======== memtest.c ========
*
This code allocates/frees memory from different memory segments.
*/
#include <std.h>
#include <log.h>
#include <mem.h>
#define NALLOCS 2 /* # of allocations from each segment */
#define BUFSIZE 128 /* size of allocations */
/* "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);
}

Table of Contents

Other manuals for Texas Instruments TMS320

Related product manuals