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);
41 static void Free (unsigned char* P)
42 /* Check a memory block and free it */
46 /* Get the size of the block */
47 unsigned char Size = P[0];
50 for (I = 1; I < Size; ++I) {
52 printf ("Scan failed - expected %02X, got %02X\n",
63 static void FillArray (void)
64 /* Fill the array with randomly allocated memory chunks */
75 static void ShowInfo (void)
78 printf ("%04X %04X %04X %04X %04X\n",
79 _horg, _hptr, _hend, _hfirst, _hlast);
84 static void Test1 (void)
89 for (I = 0; I < 0x80; ++I) {
98 static void Test2 (void)
118 static void Test3 (void)
151 static void Test4 (void)
178 /* Show info at start */
181 /* Remember the time */
190 /* Calculate the time and print it */
192 printf ("Time needed: %lu ticks\n", T);