2000-07-22 11:14:00 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2020-08-14 19:07:39 +00:00
|
|
|
#include <_heap.h>
|
2000-07-22 11:14:00 +00:00
|
|
|
|
2021-12-25 08:57:18 +00:00
|
|
|
static char* V[256];
|
2000-07-22 11:14:00 +00:00
|
|
|
|
|
|
|
static void ShowInfo (void)
|
|
|
|
/* Show heap info */
|
|
|
|
{
|
|
|
|
/* Count free blocks */
|
|
|
|
unsigned Count = 0;
|
2020-08-14 19:07:39 +00:00
|
|
|
unsigned** P = (unsigned**) _heapfirst;
|
2000-07-22 11:14:00 +00:00
|
|
|
while (P) {
|
2013-05-09 11:56:54 +00:00
|
|
|
++Count;
|
|
|
|
P = P[1];
|
2000-07-22 11:14:00 +00:00
|
|
|
}
|
|
|
|
printf ("%04X %04X %04X %04X %04X %u\n",
|
2020-08-14 19:07:39 +00:00
|
|
|
_heaporg, _heapptr, _heapend, _heapfirst, _heaplast, Count);
|
2000-07-22 11:14:00 +00:00
|
|
|
|
|
|
|
if (Count) {
|
2020-08-14 19:07:39 +00:00
|
|
|
P = (unsigned**) _heapfirst;
|
2013-05-09 11:56:54 +00:00
|
|
|
while (P) {
|
|
|
|
printf ("%04X %04X %04X %04X(%u)\n",
|
|
|
|
(unsigned) P, P[2], P[1], P[0], P[0]);
|
|
|
|
P = P[1];
|
|
|
|
}
|
|
|
|
getchar ();
|
2000-07-22 11:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char* RandStr (void)
|
|
|
|
/* Create a random string */
|
|
|
|
{
|
|
|
|
static char S [300];
|
|
|
|
unsigned Len = (rand () & 0xFF) + (sizeof (S) - 0xFF - 1);
|
|
|
|
unsigned I;
|
|
|
|
char C;
|
|
|
|
|
|
|
|
for (I = 0; I < Len; ++I) {
|
2013-05-09 11:56:54 +00:00
|
|
|
do {
|
|
|
|
C = rand() & 0xFF;
|
|
|
|
} while (C == 0);
|
|
|
|
S[I] = C;
|
2000-07-22 11:14:00 +00:00
|
|
|
}
|
|
|
|
S[Len] = '\0';
|
|
|
|
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void FillArray (void)
|
|
|
|
/* Fill the string array */
|
|
|
|
{
|
|
|
|
unsigned char I = 0;
|
|
|
|
do {
|
2013-05-09 11:56:54 +00:00
|
|
|
V[I] = strdup (RandStr ());
|
|
|
|
++I;
|
2000-07-22 11:14:00 +00:00
|
|
|
} while (I != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void FreeArray (void)
|
|
|
|
/* Free all strings in the array */
|
|
|
|
{
|
|
|
|
unsigned char I = 0;
|
|
|
|
do {
|
2013-05-09 11:56:54 +00:00
|
|
|
free (V[I]);
|
|
|
|
++I;
|
2000-07-22 11:14:00 +00:00
|
|
|
} while (I != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main (void)
|
|
|
|
{
|
|
|
|
unsigned long T;
|
|
|
|
|
|
|
|
/* Show info at start */
|
|
|
|
ShowInfo ();
|
2020-08-26 13:08:17 +00:00
|
|
|
#if !defined(__APPLE2__)
|
2000-07-22 11:14:00 +00:00
|
|
|
/* Remember the time */
|
|
|
|
T = clock ();
|
2020-08-26 13:08:17 +00:00
|
|
|
#endif
|
2000-07-22 11:14:00 +00:00
|
|
|
/* Do the tests */
|
|
|
|
FillArray ();
|
|
|
|
ShowInfo ();
|
|
|
|
FreeArray ();
|
|
|
|
ShowInfo ();
|
|
|
|
|
2020-08-26 13:08:17 +00:00
|
|
|
#if !defined(__APPLE2__)
|
2000-07-22 11:14:00 +00:00
|
|
|
/* Calculate the time and print it */
|
|
|
|
T = clock () - T;
|
|
|
|
printf ("Time needed: %lu ticks\n", T);
|
2020-08-26 13:08:17 +00:00
|
|
|
#endif
|
2000-07-22 11:14:00 +00:00
|
|
|
|
|
|
|
/* Done */
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|