home *** CD-ROM | disk | FTP | other *** search
- /* Prog to test the HeapDisplay/StubsHack library */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
-
- #include "HeapGraph.HeapGraph.h"
- #include "HeapGraph.Debug.h"
-
-
-
-
- #define Utils_Rnd() ( (double) rand() / ( RAND_MAX+1.0))
- /*double Utils_Rnd( void); */
- /* Returns random double y, 0 <= y <1 */
-
- #define Utils_RndInt( x) ( (int) (Utils_Rnd() * ((double) x)) )
- /* int Utils_RndInt( int x); */
- /* Returns random integer from { 0, 1, ... x-1 }. */
- /* Have to use ((double) x) instead of (double)(x) */
- /* in case x is 'a-b' - get a loss of precision warning */
- /* otherwise */
-
-
-
-
-
- #define N 8
-
-
- int main( void)
- {
- void *pointers[ N];
- int i;
- clock_t t1, t2;
-
-
- HeapGraph_RedirectAllocFns( NULL);
-
- printf( "Started...\n");
-
-
- for ( i=0; i<N; i++) pointers[i] = NULL;
-
- t1 = clock();
-
- /* Let's do some allocating... */
- for(;;) {
-
- int operation = Utils_RndInt( 3);
- int size = Utils_RndInt( 512) + 128;
- int p = Utils_RndInt( N);
-
- HeapGraph_SetReference( Utils_RndInt( 8));
-
- if ( operation == 0 && pointers[ p] == NULL)
- pointers[ p] = malloc( size);
-
- else if ( operation == 1 && pointers[ p] != NULL)
- pointers[ p] = realloc( pointers[ p], size);
-
- else if ( operation == 2 && pointers[ p] != NULL) {
- free( pointers[ p]);
- pointers[ p] = NULL;
- }
-
- t2 = clock();
- if ( t2-t1 > CLOCKS_PER_SEC*2) {
- printf( ".");
-
- Debug_Printf( "This text is from a call to Debug_Printf. ");
- Debug_Printf( "The Last operation was type %i, pointers[p]=%x, p=%i\n",
- operation, pointers[p], p
- );
-
- HeapGraph_Sendf( "This text is from a call to HeapGraph_Sendf\n");
-
- t1 = t2;
- }
- }
-
-
- return 0;
- }
-