Example of Memory Allocation Libraries’ APIs- Resident

 1 /*
 2  *        main.c 
 3  *
 4  *        To demonstrate APIs related to K 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 *Kptrm, *Kptrc, *Kptrr;
31 
32   Kptrm = Kmalloc (size);
33   printf ("Kmalloc returns = %x\n", Kptrm);
34 
35   Kptrc = Kcalloc (nmemb, size);
36   printf ("Kcalloc returns = %x\n", Kptrc);
37 
38   Kptrr = Krealloc (Kptrm, size);
39   printf ("Krealloc returns = %x\n", Kptrr);
40 
41   Kfree (Kptrc);
42   printf ("Kfree done\n");
43 
44 //exit:
45   printf ("main ended\n\n");
46   return 0;
47 }

Comments

Click here to Post a Comment