gcc config
[prop.git] / lib-src / memory / qa.cc
blobae93c0ef4808d3ef41093e3ab06ae1150f4fd966
1 //////////////////////////////////////////////////////////////////////////////
2 // NOTICE:
3 //
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
9 // your programs.
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
16 // code.
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
21 // Allen Leung
22 // 1994
23 //////////////////////////////////////////////////////////////////////////////
25 #include <stdio.h>
26 #include <string.h>
27 #include <assert.h>
28 #include <AD/memory/arena.h> // Arenas
29 #include <AD/memory/boundtag.h> // Boundary tag memory manager
30 #include <AD/memory/buddy.h> // Fibonacci buddy system
31 #include <AD/memory/mempool.h> // Memory pool
32 #include <AD/memory/strpool.h> // String pool
34 int main(int argc, char * argv[])
36 StringPool A; MemPool B;
37 BoundaryTag C(4096);
38 int i;
40 A["Shure"];
41 A["Waters"];
42 B[100];
44 void * core[257];
46 for (i = 0; i < 257; i++)
47 { core[i] = C[i]; memset(core[i],255,i);
49 printf("\n");
51 BoundaryTag::Statistics S = C.statistics();
52 printf("pages = %d\n", S.page_count);
53 printf("bytes allocated = %d\n", S.bytes_allocated);
54 printf("bytes available = %d\n", S.bytes_available);
55 printf("free blocks = %d\n", S.free_block_count);
57 i = 0;
58 do {
59 i = (i+8) % 257;
60 C.free(core[i]);
61 } while (i != 0);
62 printf("\n");
64 S = C.statistics();
66 printf("pages = %d\n", S.page_count);
67 printf("bytes allocated = %d\n", S.bytes_allocated);
68 printf("bytes available = %d\n", S.bytes_available);
69 printf("free blocks = %d\n", S.free_block_count);
71 // Arena arena(100);
73 // double * x = arena();
74 // double * y = arena();
76 // arena.free(x); arena.free(y);
78 char block[70*1024];
79 Buddy buddy(block, sizeof(block));
81 for (i = 0; i < 257; i++)
82 { core[i] = buddy[i]; memset(core[i],255,i); }
83 printf("\n");
85 i = 0;
86 do {
87 i = (i+8) % 257;
88 buddy.free(core[i]);
89 } while (i != 0);
90 printf("\n");
93 printf("OK\n");
94 return 0;