summaryrefslogtreecommitdiff
path: root/noncore/settings/aqpkg/mem.cpp
Unidiff
Diffstat (limited to 'noncore/settings/aqpkg/mem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/mem.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/noncore/settings/aqpkg/mem.cpp b/noncore/settings/aqpkg/mem.cpp
new file mode 100644
index 0000000..76ce35c
--- a/dev/null
+++ b/noncore/settings/aqpkg/mem.cpp
@@ -0,0 +1,105 @@
1/***************************************************************************
2 mem.h - description
3 -------------------
4 begin : Mon Aug 26 2002
5 copyright : (C) 2002 by Andy Qua
6 email : andy.qua@blueyonder.co.uk
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#include <stdio.h>
18#include <fstream>
19#include <list>
20using namespace std;
21
22#define __MEMFILE_C
23#include "global.h"
24
25#ifdef _DEBUG
26
27void __cdecl *operator new( unsigned int size, const char *file, int line )
28{
29 void *ptr = (void *)malloc(size);
30 AddTrack((long)ptr, size, file, line);
31 return(ptr);
32}
33
34void operator delete(void *p)
35{
36 RemoveTrack((long)p);
37 free(p);
38}
39
40#endif
41
42
43typedef struct {
44 longaddress;
45 longsize;
46 charfile[64];
47 longline;
48} ALLOC_INFO;
49
50typedef list<ALLOC_INFO*> AllocList;
51
52AllocList allocList;
53
54
55
56void AddTrack(long addr, long asize, const char *fname, long lnum)
57{
58 ALLOC_INFO *info;
59
60
61 info = (ALLOC_INFO *)malloc(sizeof( ALLOC_INFO ));
62 info->address = addr;
63 strncpy(info->file, fname, 63);
64 info->line = lnum;
65 info->size = asize;
66 allocList.insert(allocList.begin(), info);
67};
68
69void RemoveTrack(long addr)
70{
71 AllocList::iterator i;
72
73 bool found = false;
74 for(i = allocList.begin(); i != allocList.end(); i++)
75 {
76 if((*i)->address == addr)
77 {
78 allocList.remove((*i));
79 found = true;
80 break;
81 }
82 }
83}
84
85void DumpUnfreed()
86{
87 AllocList::iterator i;
88 long totalSize = 0;
89 char buf[1024];
90
91
92// if(!allocList)
93 // return;
94
95 for(i = allocList.begin(); i != allocList.end(); i++) {
96 sprintf(buf, "%-15s: LINE %ld, ADDRESS %ld %ld unfreed",
97 (*i)->file, (*i)->line, (*i)->address, (*i)->size);
98 cout <<buf << endl;
99 totalSize += (*i)->size;
100 }
101 sprintf(buf, "-----------------------------------------------------------\n");
102 cout <<buf << endl;
103 sprintf(buf, "Total Unfreed: %ld bytes\n", totalSize);
104 cout <<buf << endl;
105};