8 extern unsigned _horg; /* Bottom of heap */
9 extern unsigned _hptr; /* Current top */
10 extern unsigned _hend; /* Upper limit */
11 extern unsigned _hfirst; /* First free block in list */
12 extern unsigned _hlast; /* Last free block in list */
15 static unsigned char* V[256];
19 static char* Alloc (void)
20 /* Allocate a random sized chunk of memory */
22 /* Determine the size */
23 unsigned char Size = (((unsigned char)rand()) & 0x7F) + 1;
26 unsigned char* P = malloc (Size);
28 /* Set the string to a defined value. We use the size, since this will
29 * also allow us to retrieve it later.
32 memset (P, Size, Size);
34 printf ("Could not allocate %u bytes\n", Size);
42 static void Free (unsigned char* P)
43 /* Check a memory block and free it */
47 /* Get the size of the block */
48 unsigned char Size = P[0];
51 for (I = 1; I < Size; ++I) {
53 printf ("Scan failed - expected %02X, got %02X\n",
65 static void FillArray (void)
66 /* Fill the array with randomly allocated memory chunks */
77 static void ShowInfo (void)
80 /* Count free blocks */
82 unsigned** P = (unsigned**) _hfirst;
87 printf ("%04X %04X %04X %04X %04X %u\n",
88 _horg, _hptr, _hend, _hfirst, _hlast, Count);
91 P = (unsigned**) _hfirst;
93 printf ("%04X %04X %04X %04X(%u)\n",
94 (unsigned) P, P[2], P[1], P[0], P[0]);
103 static void Test1 (void)
107 for (I = 0; I < 0x80; ++I) {
116 static void Test2 (void)
130 static void Test3 (void)
144 static void Test4 (void)
163 static void Test5 (void)
195 static void Test6 (void)
221 /* Show info at start */
224 /* Remember the time */
235 /* Calculate the time and print it */
237 printf ("Time needed: %lu ticks\n", T);