File: testDebugMemory.cpp

package info (click to toggle)
between 6%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, stretch
  • size: 3,532 kB
  • sloc: cpp: 28,110; php: 718; ansic: 638; objc: 245; sh: 236; makefile: 99; perl: 67
file content (85 lines) | stat: -rw-r--r-- 1,471 bytes parent folder | download | duplicates (30)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Modification History
 *
 * 2002-October-17 Jason Rohrer
 * Created.
 *
 * 2002-October-18  Jason Rohrer
 * Added static initialization counting class for MemoryTrack.
 *
 * 2002-October-19   Jason Rohrer
 * Removed call to debugMemoryPrintLeaksAndStopTracking.
 * Made test cases more interesting.
 * Added test cases for deleting NULL pointers.
 */


#include "minorGems/util/development/memory/debugMemory.h"


#include <stdio.h>


class TestClass {
    public:
        TestClass() {
            mX = new int[5];
            }

        ~TestClass() {
            delete [] mX;
            }
        
        int *mX;
    };



int main() {

    int *x = new int[5];

    printf( "array contents before initializing elements:\n"
            "%d, %d, %d, %d, %d\n\n",
            x[0], x[1], x[2], x[3], x[4] );
    
    x[0] = 1;
    x[1] = 2;
    x[2] = 3;
    x[3] = 4;
    x[4] = 5;

    printf( "array contents before deleting:\n"
            "%d, %d, %d, %d, %d\n\n",
            x[0], x[1], x[2], x[3], x[4] );

    delete [] x;

    printf( "array contents after deleting:\n"
            "%d, %d, %d, %d, %d\n\n",
            x[0], x[1], x[2], x[3], x[4] );

    
    int *y = new int[4];
    y[0] = 1;
    
    TestClass *t = new TestClass();

    delete t;

    int *z = new int[7];
    delete z;
    
    //delete t;

    int *badPointer = NULL;
    delete badPointer;

    int *badPointer2 = NULL;
    delete [] badPointer2;
    
    return 0;
    }