File: many-xpts.c

package info (click to toggle)
valgrind 1%3A3.14.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 156,980 kB
  • sloc: ansic: 728,128; exp: 26,134; xml: 22,268; cpp: 7,638; asm: 7,312; makefile: 6,102; perl: 5,910; sh: 5,717
file content (52 lines) | stat: -rw-r--r-- 981 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdlib.h>

#define nth_bit(x, n)   ((x >> n) & 1)
#define Fn(N, Np1) \
   void* a##N(int x) { return ( nth_bit(x, N) ? a##Np1(x) : a##Np1(x) ); }

// This test allocates a lot of heap memory, and every allocation features a
// different stack trace -- the stack traces are effectively a
// representation of the number 'i', where each function represents a bit in
// 'i', and if it's a 1 the first function is called, and if it's a 0 the
// second function is called.

void* a999(int x)
{
   return malloc(100);
}

Fn(17, 999)
Fn(16, 17)
Fn(15, 16)
Fn(14, 15)
Fn(13, 14)
Fn(12, 13)
Fn(11, 12)
Fn(10, 11)
Fn( 9, 10)
Fn( 8, 9)
Fn( 7, 8)
Fn( 6, 7)
Fn( 5, 6)
Fn( 4, 5)
Fn( 3, 4)
Fn( 2, 3)
Fn( 1, 2)
Fn( 0, 1)

int main(void)
{
   int i;

   // Create a large XTree.
   for (i = 0; i < (1 << 18); i++)
      a0(i);

   // Do a lot of allocations so it gets dup'd a lot of times.
   for (i = 0; i < 100000; i++) {
      free(a1(234));
      free(a2(111));
   }

   return 0;
}