Mercurial > vba-clojure
diff src/win32/7zip/7z/CPP/Common/NewHandler.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/7zip/7z/CPP/Common/NewHandler.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,116 @@ 1.4 +// NewHandler.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#include <stdlib.h> 1.9 + 1.10 +#include "NewHandler.h" 1.11 + 1.12 +// #define DEBUG_MEMORY_LEAK 1.13 + 1.14 +#ifndef DEBUG_MEMORY_LEAK 1.15 + 1.16 +#ifdef _WIN32 1.17 +void * 1.18 +#ifdef _MSC_VER 1.19 +__cdecl 1.20 +#endif 1.21 +operator new(size_t size) 1.22 +{ 1.23 + // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size); 1.24 + void *p = ::malloc(size); 1.25 + if (p == 0) 1.26 + throw CNewException(); 1.27 + return p; 1.28 +} 1.29 + 1.30 +void 1.31 +#ifdef _MSC_VER 1.32 +__cdecl 1.33 +#endif 1.34 +operator delete(void *p) throw() 1.35 +{ 1.36 + /* 1.37 + if (p == 0) 1.38 + return; 1.39 + ::HeapFree(::GetProcessHeap(), 0, p); 1.40 + */ 1.41 + ::free(p); 1.42 +} 1.43 +#endif 1.44 + 1.45 +#else 1.46 + 1.47 +#pragma init_seg(lib) 1.48 +const int kDebugSize = 1000000; 1.49 +static void *a[kDebugSize]; 1.50 +static int index = 0; 1.51 + 1.52 +static int numAllocs = 0; 1.53 +void * __cdecl operator new(size_t size) 1.54 +{ 1.55 + numAllocs++; 1.56 + void *p = HeapAlloc(GetProcessHeap(), 0, size); 1.57 + if (index == 40) 1.58 + { 1.59 + int t = 1; 1.60 + } 1.61 + if (index < kDebugSize) 1.62 + { 1.63 + a[index] = p; 1.64 + index++; 1.65 + } 1.66 + if (p == 0) 1.67 + throw CNewException(); 1.68 + printf("Alloc %6d, size = %8d\n", numAllocs, size); 1.69 + return p; 1.70 +} 1.71 + 1.72 +class CC 1.73 +{ 1.74 +public: 1.75 + CC() 1.76 + { 1.77 + for (int i = 0; i < kDebugSize; i++) 1.78 + a[i] = 0; 1.79 + } 1.80 + ~CC() 1.81 + { 1.82 + for (int i = 0; i < kDebugSize; i++) 1.83 + if (a[i] != 0) 1.84 + return; 1.85 + } 1.86 +} g_CC; 1.87 + 1.88 + 1.89 +void __cdecl operator delete(void *p) 1.90 +{ 1.91 + if (p == 0) 1.92 + return; 1.93 + /* 1.94 + for (int i = 0; i < index; i++) 1.95 + if (a[i] == p) 1.96 + a[i] = 0; 1.97 + */ 1.98 + HeapFree(GetProcessHeap(), 0, p); 1.99 + numAllocs--; 1.100 + printf("Free %d\n", numAllocs); 1.101 +} 1.102 + 1.103 +#endif 1.104 + 1.105 +/* 1.106 +int MemErrorVC(size_t) 1.107 +{ 1.108 + throw CNewException(); 1.109 + // return 1; 1.110 +} 1.111 +CNewHandlerSetter::CNewHandlerSetter() 1.112 +{ 1.113 + // MemErrorOldVCFunction = _set_new_handler(MemErrorVC); 1.114 +} 1.115 +CNewHandlerSetter::~CNewHandlerSetter() 1.116 +{ 1.117 + // _set_new_handler(MemErrorOldVCFunction); 1.118 +} 1.119 +*/