* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / tests / grab.c
blobb65fa28042054849d3a7d56c740952c168b7e395
2 #include <stdio.h>
3 #include <malloc.h>
5 struct s
7 struct s * n;
8 char v[1];
9 };
11 #define M ((unsigned)-1>>1)
12 #define V (M^(M>>1))
14 main (argc,argv)
15 int argc;
16 char ** argv;
18 struct s * ptr1 = 0;
19 struct s * ptr2;
20 struct s * ptr3;
21 int i,sz;
22 unsigned long total = 0;
24 for(i=0, sz=256 ; i<32; i++, sz = ((sz << 1) | (sz & V)) & M)
26 ptr2 = (struct s *) malloc(sz-sizeof(int));
27 printf("%2d(%8u)..%08lx..%ld\n",i,sz,(long)ptr2,(long)ptr2);
28 if(ptr2==0) break;
29 total+=sz;
30 if(ptr1==0)
32 ptr1 = ptr3 = ptr2;
33 ptr3->n = 0;
35 else
37 ptr3->n = ptr2;
38 ptr3 = ptr2;
39 ptr3->n = 0;
42 for(sz>>=1; sz>3; )
44 ptr2 = (struct s *) malloc(sz-sizeof(int));
45 if(ptr2==0) { sz >>=1; continue; }
46 printf("%2d(%8u)..%08lx..%ld\n",i++,sz,(long)ptr2,(long)ptr2);
47 total+=sz;
48 if(ptr1==0)
50 ptr1 = ptr3 = ptr2;
51 ptr3->n = 0;
53 else
55 ptr3->n = ptr2;
56 ptr3 = ptr2;
57 ptr3->n = 0;
60 printf("Free all - total was %ldK bytes\n", total/1024);
61 while( ptr1 )
63 ptr3 = ptr1->n;
64 free(ptr1);
65 ptr1 = ptr3;
67 ptr2 = (struct s *) malloc(200);
68 printf("%2d(%8u)..%08lx..%ld\n",i++,200,(long)ptr2,(long)ptr2);
69 ptr2 = (struct s *) malloc(30000);
70 printf("%2d(%8u)..%08lx..%ld\n",i++,30000,(long)ptr2,(long)ptr2);
71 ptr2 = (struct s *) malloc(20000);
72 printf("%2d(%8u)..%08lx..%ld\n",i++,20000,(long)ptr2,(long)ptr2);
73 sz = (256<<sizeof(int));
76 ptr2 = (struct s *) malloc(sz-sizeof(int));
77 printf("%2d(%8u)..%08lx..%ld\n",i++,sz,(long)ptr2,(long)ptr2);
79 while(ptr2 && i < 100);
80 exit(0);