EasyManuals Logo

Texas Instruments TMS320 User Manual

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
Page #192 background imageLoading...
Page #192 background image
Memory Management
5-10
Example 5-8. Memory Allocation (C6000 Platform)
/* ======== memtest.c ========
* This program allocates and 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;
extern Int IDRAM;
static Void printmem(Int segid);
/*
* ======== main ========
*/
Void main()
{
Int i;
Ptr ram[NALLOCS];
LOG_printf(&trace, "before allocating ...");
/* print initial memory status */
printmem(IDRAM);
LOG_printf(&trace, "allocating ...");
/* allocate some memory from each segment */
for (i = 0; i < NALLOCS; i++) {
ram[i] = MEM_alloc(IDRAM, BUFSIZE, 0);
LOG_printf(&trace, "seg %d: ptr = 0x%x", IDRAM, ram[i]);
}
LOG_printf(&trace, "after allocating ...");
/* print memory status */
printmem(IDRAM);
/* free memory */
for (i = 0; i < NALLOCS; i++) {
MEM_free(IDRAM, ram[i], BUFSIZE);
}
LOG_printf(&trace, "after freeing ...");
/* print memory status */
printmem(IDRAM);
}
/*
* ======== 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

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Texas Instruments TMS320 and is the answer not in the manual?

Texas Instruments TMS320 Specifications

General IconGeneral
BrandTexas Instruments
ModelTMS320
CategoryComputer Hardware
LanguageEnglish

Related product manuals