File: markers.cc

package info (click to toggle)
libcwd 1.0.4-1.1
  • links: PTS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 8,136 kB
  • ctags: 10,313
  • sloc: cpp: 23,354; sh: 9,798; ansic: 1,172; makefile: 852; exp: 234; awk: 11
file content (71 lines) | stat: -rw-r--r-- 1,521 bytes parent folder | download | duplicates (5)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <libcwd/sys.h>
#include <libcwd/debug.h>

// A dummy class
class A {
  int i;
  int j;
  char k;
};

int main(int argc, char* argv[])
{
  // Don't show allocations that are allocated before main()
  Debug( make_all_allocations_invisible_except(NULL) );

  // Select channels
  ForAllDebugChannels( if (debugChannel.is_on()) debugChannel.off() );
  Debug( dc::notice.on() );
  Debug( dc::malloc.on() );
  Debug( dc::warning.on() );
  // Debug( dc::bfd.on() );

  // Write debug output to cout
  Debug( libcw_do.set_ostream(&cout) );

  // Turn debug object on
  Debug( libcw_do.on() ); 

  // Allocate new object
  A* a1 = new A;
  AllocTag(a1, "First created");

#if CWDEBUG_MARKER
  // Create marker
  libcwd::marker_ct* marker = new libcwd::marker_ct("A test marker");
#endif

  // Allocate more objects
  A* a2 = new A[10];
  AllocTag(a2, "Created after the marker");
  int* p = new int[30];
  AllocTag(p, "Created after the marker");

  // Show Memory Allocation Overview
  Debug( list_allocations_on(libcw_do) );

  Dout(dc::notice, "Moving the int array outside of the marker...");
#if CWDEBUG_MARKER
  Debug( move_outside(marker, p) );
#endif

  // Show Memory Allocation Overview
  Debug( list_allocations_on(libcw_do) );

#if CWDEBUG_MARKER
  // Delete the marker
  delete marker;
#endif

#if CWDEBUG_ALLOC
  Dout(dc::notice, "Finished successfully.");
#else
  DoutFatal(dc::fatal, "Please reconfigure libcwd with --enable-alloc.");
#endif
  return 0;
}