File: debugMemory.cpp

package info (click to toggle)
between 6%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,532 kB
  • sloc: cpp: 28,110; php: 718; ansic: 638; objc: 245; sh: 236; makefile: 97; perl: 67
file content (95 lines) | stat: -rw-r--r-- 2,187 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
86
87
88
89
90
91
92
93
94
95
/*
 * 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
 * Added more detail to error message.
 * Improved printing behavior.
 * Moved include of debugMemory.h to work better with IDE compilers.
 * Fixed to deal with differences between malloc and new[] on some platforms.
 *
 * 2002-October-20  Jason Rohrer
 * Removed delete macro trick that was causing crashes in tinyxml.
 * Removed function that was no longer being used.
 */



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


#ifdef DEBUG_MEMORY

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

#include "stdlib.h"
#include "stdio.h"



void *debugMemoryNew( unsigned int inSize,
                      const char *inFileName, int inLine ) {

    
    void *allocatedPointer = (void *)malloc( inSize );

    MemoryTrack::addAllocation( allocatedPointer, inSize,
                                SINGLE_ALLOCATION,
                                inFileName, inLine );
    
    return allocatedPointer;    
    }



void *debugMemoryNewArray( unsigned int inSize,
                           const char *inFileName, int inLine ) {

    unsigned int mallocSize = inSize;
    if( inSize == 0 ) {
        // always allocate at least one byte to circumvent differences
        // between malloc and new[] on some platforms
        // (new int[0] returns a pointer to an array of length 0, while
        //  malloc( 0 ) can return NULL on some platforms)
        mallocSize = 1;
        }

    void *allocatedPointer = (void *)malloc( mallocSize );

    MemoryTrack::addAllocation( allocatedPointer, inSize,
                                ARRAY_ALLOCATION,
                                inFileName, inLine );
    
    return allocatedPointer;    
    }



void debugMemoryDelete( void *inPointer ) {
    MemoryTrack::addDeallocation( inPointer, SINGLE_ALLOCATION );
    free( inPointer );
    }



void debugMemoryDeleteArray( void *inPointer ) {
    MemoryTrack::addDeallocation( inPointer, ARRAY_ALLOCATION );
    free( inPointer );
    }



#endif