Memory Management
Memory and Low-level Functions
5-9
Example 5-7.
Memory Allocation (C5000 and C28x Platform
s
)
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);
}
Содержание TMS320 Series
Страница 1: ...TMS320 DSP BIOS v5 40 User s Guide Literature Number SPRU423G April 2009 ...
Страница 16: ...xvi ...
Страница 152: ...Tasks 4 48 Figure 4 12 Trace from Example 4 7 ...
Страница 168: ...Semaphores 4 64 Figure 4 14 Trace Results from Example 4 11 ...
Страница 202: ...5 20 ...
Страница 287: ...Index 9 Index Void 1 11 W words data memory 3 15 of code 1 5 wrapper function 2 29 ...
Страница 288: ...Index 10 Index ...