Example of Memory Allocation Libraries’ APIs- Non-resident

 1 /*
 2  *        main.c 
 3  *
 4  *        To demonstrate APIs related to memory allocation libraries
 5  */
 6 
 7 #include <basic.h>
 8 #include <tk/tkernel.h>
 9 #include <stdio.h>
10 #ifdef DEBUG
11 #include <util/tmonitor.h>
12 #endif
13 
14 
15 
16 /******************************************************************************
17 main
18 ******************************************************************************/
19 EXPORT ER
20 main (INT ac, UB * av[])
21 {
22 
23 #ifdef DEBUG
24   tm_monitor ();
25 #endif
26   printf ("main: (ac = %d)\n", ac);
27 
28 
29   size_t size = 8, nmemb = 8;
30   VP *Vptrm, *Vptrc, *Vptrr;
31 
32   Vptrm = Vmalloc (size);
33   printf ("Vmalloc returns = %x\n", Vptrm);
34 
35   Vptrc = Vcalloc (nmemb, size);
36   printf ("Vcalloc returns = %x\n", Vptrc);
37 
38   Vptrr = Vrealloc (Vptrm, size);
39   printf ("Vrealloc returns = %x\n", Vptrr);
40 
41   Vfree (Vptrc);
42   printf ("Vfree done\n");
43 
44 //exit:
45   printf ("main ended\n\n");
46   return 0;
47 }

Comments

Click here to Post a Comment