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.cpp216
1 files changed, 110 insertions, 106 deletions
diff --git a/noncore/settings/aqpkg/mem.cpp b/noncore/settings/aqpkg/mem.cpp
index 405aada..5f32a26 100644
--- a/noncore/settings/aqpkg/mem.cpp
+++ b/noncore/settings/aqpkg/mem.cpp
@@ -1,106 +1,110 @@
1/*************************************************************************** 1/*
2 mem.h - description 2                This file is part of the OPIE Project
3 ------------------- 3
4 begin : Mon Aug 26 2002 4 =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk>
5 copyright : (C) 2002 by Andy Qua 5             .=l. Dan Williams <drw@handhelds.org>
6 email : andy.qua@blueyonder.co.uk 6           .>+-=
7 ***************************************************************************/ 7 _;:,     .>    :=|. This file is free software; you can
8 8.> <`_,   >  .   <= redistribute it and/or modify it under
9/*************************************************************************** 9:`=1 )Y*s>-.--   : the terms of the GNU General Public
10 * * 10.="- .-=="i,     .._ License as published by the Free Software
11 * This program is free software; you can redistribute it and/or modify * 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12 * it under the terms of the GNU General Public License as published by * 12     ._= =}       : or (at your option) any later version.
13 * the Free Software Foundation; either version 2 of the License, or * 13    .%`+i>       _;_.
14 * (at your option) any later version. * 14    .i_,=:_.      -<s. This file is distributed in the hope that
15 * * 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16 ***************************************************************************/ 16    : ..    .:,     . . . without even the implied warranty of
17#include <stdio.h> 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18#include <fstream> 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
19#include <iostream> 19..}^=.=       =       ; Public License for more details.
20#include <list> 20++=   -.     .`     .:
21using namespace std; 21 :     =  ...= . :.=- You should have received a copy of the GNU
22 22 -.   .:....=;==+<; General Public License along with this file;
23#define __MEMFILE_C 23  -_. . .   )=.  = see the file COPYING. If not, write to the
24#include "global.h" 24    --        :-=` Free Software Foundation, Inc.,
25 25 59 Temple Place - Suite 330,
26#ifdef _DEBUG 26 Boston, MA 02111-1307, USA.
27 27
28void __cdecl *operator new( unsigned int size, const char *file, int line ) 28*/
29{ 29
30 void *ptr = (void *)malloc(size); 30#include <stdio.h>
31 AddTrack((long)ptr, size, file, line); 31#include <list>
32 return(ptr); 32using namespace std;
33} 33
34 34#define __MEMFILE_C
35void operator delete(void *p) 35#include "global.h"
36{ 36
37 RemoveTrack((long)p); 37#ifdef _DEBUG
38 free(p); 38
39} 39void __cdecl *operator new( unsigned int size, const char *file, int line )
40 40{
41#endif 41 void *ptr = (void *)malloc(size);
42 42 AddTrack((long)ptr, size, file, line);
43 43 return(ptr);
44typedef struct { 44}
45 longaddress; 45
46 longsize; 46void operator delete(void *p)
47 charfile[64]; 47{
48 longline; 48 RemoveTrack((long)p);
49} ALLOC_INFO; 49 free(p);
50 50}
51typedef list<ALLOC_INFO*> AllocList; 51
52 52#endif
53AllocList allocList; 53
54 54
55 55typedef struct {
56 56 longaddress;
57void AddTrack(long addr, long asize, const char *fname, long lnum) 57 longsize;
58{ 58 charfile[64];
59 ALLOC_INFO *info; 59 longline;
60 60} ALLOC_INFO;
61 61
62 info = (ALLOC_INFO *)malloc(sizeof( ALLOC_INFO )); 62typedef list<ALLOC_INFO*> AllocList;
63 info->address = addr; 63
64 strncpy(info->file, fname, 63); 64AllocList allocList;
65 info->line = lnum; 65
66 info->size = asize; 66
67 allocList.insert(allocList.begin(), info); 67
68}; 68void AddTrack(long addr, long asize, const char *fname, long lnum)
69 69{
70void RemoveTrack(long addr) 70 ALLOC_INFO *info;
71{ 71
72 AllocList::iterator i; 72
73 73 info = (ALLOC_INFO *)malloc(sizeof( ALLOC_INFO ));
74 bool found = false; 74 info->address = addr;
75 for(i = allocList.begin(); i != allocList.end(); i++) 75 strncpy(info->file, fname, 63);
76 { 76 info->line = lnum;
77 if((*i)->address == addr) 77 info->size = asize;
78 { 78 allocList.insert(allocList.begin(), info);
79 allocList.remove((*i)); 79};
80 found = true; 80
81 break; 81void RemoveTrack(long addr)
82 } 82{
83 } 83 AllocList::iterator i;
84} 84
85 85 bool found = false;
86void DumpUnfreed() 86 for(i = allocList.begin(); i != allocList.end(); i++)
87{ 87 {
88 AllocList::iterator i; 88 if((*i)->address == addr)
89 long totalSize = 0; 89 {
90 char buf[1024]; 90 allocList.remove((*i));
91 91 found = true;
92 92 break;
93// if(!allocList) 93 }
94 // return; 94 }
95 95}
96 for(i = allocList.begin(); i != allocList.end(); i++) { 96
97 sprintf(buf, "%-15s: LINE %ld, ADDRESS %ld %ld unfreed", 97void DumpUnfreed()
98 (*i)->file, (*i)->line, (*i)->address, (*i)->size); 98{
99 cout <<buf << endl; 99 AllocList::iterator i;
100 totalSize += (*i)->size; 100 long totalSize = 0;
101 } 101 char buf[1024];
102 sprintf(buf, "-----------------------------------------------------------\n"); 102
103 cout <<buf << endl; 103 for(i = allocList.begin(); i != allocList.end(); i++) {
104 sprintf(buf, "Total Unfreed: %ld bytes\n", totalSize); 104 sprintf(buf, "%-15s: LINE %ld, ADDRESS %ld %ld unfreed",
105 cout <<buf << endl; 105 (*i)->file, (*i)->line, (*i)->address, (*i)->size);
106}; 106 totalSize += (*i)->size;
107 }
108 sprintf(buf, "-----------------------------------------------------------\n");
109 sprintf(buf, "Total Unfreed: %ld bytes\n", totalSize);
110};