1 |
/************************************************************************** |
2 |
* This code is part of the supporting infrastructure for ATA Mapper. |
3 |
* Copyright (C) 2002,2003,2004 Applera Corporation. All rights reserved. |
4 |
* Author: Nathan Edwards |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received (LICENSE.txt) a copy of the GNU General Public |
17 |
* License along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*************************************************************************/ |
20 |
|
21 |
|
22 |
#ifndef _IBPEP_memory_debug_h_ |
23 |
#define _IBPEP_memory_debug_h_ |
24 |
|
25 |
#include <stdio.h> |
26 |
|
27 |
#define QUOTE(a) #a |
28 |
|
29 |
#define outputsizeof(os,type) os << "sizeof(" << QUOTE(type) << ") = " << sizeof(type) << endl |
30 |
|
31 |
#ifdef DEBUG_MEMORY |
32 |
|
33 |
#define NEW_DIAGNOSTIC(t,p,b,f,l) \ |
34 |
fprintf(stderr,"0x%p = %s::new(%ld)[%s:%d]\n",p,t,b,f,l) |
35 |
|
36 |
#define DELETE_DIAGNOSTIC(t,p,b,f,l) \ |
37 |
fprintf(stderr,"%s::delete(0x%p,%ld)[%s:%d]\n",t,p,b,f,l) |
38 |
|
39 |
#define ARRAYNEW_DIAGNOSTIC(t,p,b,f,l) \ |
40 |
fprintf(stderr,"0x%p = %s::new[](%ld)[%s:%d]\n",p,t,b,f,l) |
41 |
|
42 |
#define ARRAYDELETE_DIAGNOSTIC(t,p,b,f,l) \ |
43 |
fprintf(stderr,"%s::delete[](0x%p,%ld)[%s:%d]\n",t,p,b,f,l) |
44 |
|
45 |
#define MEMORY_DEBUG(type) \ |
46 |
\ |
47 |
void* operator new(size_t bytes)\ |
48 |
{ \ |
49 |
void *p = ::operator new(bytes); \ |
50 |
NEW_DIAGNOSTIC(QUOTE(type),p,bytes,__FILE__,__LINE__);\ |
51 |
return p;\ |
52 |
}\ |
53 |
void* operator new [] (size_t bytes)\ |
54 |
{ \ |
55 |
void *p = ::operator new[](bytes); \ |
56 |
ARRAYNEW_DIAGNOSTIC(QUOTE(type),p,bytes,__FILE__,__LINE__);\ |
57 |
return p;\ |
58 |
}\ |
59 |
\ |
60 |
void* operator new (unsigned int bytes, void * const & p0)\ |
61 |
{ \ |
62 |
void *p = ::operator new (bytes,p0); \ |
63 |
NEW_DIAGNOSTIC(QUOTE(type),p,bytes,__FILE__,__LINE__);\ |
64 |
return p;\ |
65 |
}\ |
66 |
\ |
67 |
void operator delete(void* p, size_t bytes)\ |
68 |
{ ::operator delete(p);\ |
69 |
DELETE_DIAGNOSTIC(QUOTE(type),p,bytes,__FILE__,__LINE__);\ |
70 |
}\ |
71 |
\ |
72 |
void operator delete[](void* p, size_t bytes)\ |
73 |
{ ::operator delete[](p);\ |
74 |
ARRAYDELETE_DIAGNOSTIC(QUOTE(type),p,bytes,__FILE__,__LINE__);\ |
75 |
}\ |
76 |
|
77 |
|
78 |
#else |
79 |
|
80 |
#define MEMORY_DEBUG(type) |
81 |
|
82 |
#endif |
83 |
|
84 |
#endif |