• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <stdlib.h>
3 
4 #define NLIVE 1000000
5 
6 #define NITERS (3*1000*1000)
7 
8 char* arr[NLIVE];
9 
main(void)10 int main ( void )
11 {
12    int i, j, nbytes = 0;
13    printf("initialising\n");
14    for (i = 0; i < NLIVE; i++)
15       arr[i] = NULL;
16 
17    printf("running\n");
18    j = -1;
19    for (i = 0; i < NITERS; i++) {
20       j++;
21       if (j == NLIVE) j = 0;
22       if (arr[j])
23          free(arr[j]);
24       arr[j] = malloc(nbytes);
25 
26       // Cycle through the sizes 0,8,16,24,32.  Zero will get rounded up to
27       // 8, so the 8B bucket will get twice as much traffic.
28       nbytes += 8;
29       if (nbytes > 32)
30          nbytes = 0;
31    }
32 
33    for (i = 0; i < NLIVE; i++)
34       if (arr[i])
35          free(arr[i]);
36 
37    printf("done\n");
38    return 0;
39 }
40