• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

contrib/maloc/tools/tests/zfence/tstheap.c

00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <math.h>
00004 #include <limits.h>
00005 
00006 #include <efence.h>
00007 
00008 /*
00009  * This is a simple program to exercise the allocator. It allocates and frees
00010  * memory in a pseudo-random fashion. It should run silently, using up time
00011  * and resources on your system until you stop it or until it has gone
00012  * through TEST_DURATION (or the argument) iterations of the loop.
00013  */
00014 
00015 extern C_LINKAGE double drand48(void); /* For pre-ANSI C systems */
00016 
00017 #define    POOL_SIZE  1024
00018 #define    LARGEST_BUFFER        30000
00019 #define    TEST_DURATION         1000000
00020 
00021 void *     pool[POOL_SIZE];
00022 
00023 #ifdef     FAKE_DRAND48
00024 /*
00025  * Add -DFAKE_DRAND48 to your compile flags if your system doesn't
00026  * provide drand48().
00027  */
00028 
00029 #ifndef    ULONG_MAX
00030 #define    ULONG_MAX  ~(1L)
00031 #endif
00032 
00033 double
00034 drand48(void)
00035 {
00036            return (random() / (double)ULONG_MAX);
00037 }
00038 #endif
00039 
00040 int
00041 main(int argc, char * * argv)
00042 {
00043            int        count = 0;
00044            int        duration = TEST_DURATION;
00045 
00046            if ( argc >= 2 )
00047                       duration = atoi(argv[1]);
00048 
00049            for ( ; count < duration; count++ ) {
00050                       void * *   element = &pool[(int)(drand48() * POOL_SIZE)];
00051                       size_t                size = (size_t)(drand48() * (LARGEST_BUFFER + 1));
00052 
00053                       if ( *element ) {
00054                                  free( *element );
00055                                  *element = 0;
00056                       }
00057                       else if ( size > 0 ) {
00058                                  *element = malloc(size);
00059                       }
00060            }
00061            return 0;
00062 }

Generated on Wed Oct 20 2010 11:12:15 for APBS by  doxygen 1.7.2