aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/NewHandler.cpp
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2022-06-20 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2023-12-17 13:35:20 +0500
commita3e1d227377188734b82f023f96f8e25dc40f3e6 (patch)
tree23cad8d47eb23d26ea727b4f7f4a65124f724065 /CPP/Common/NewHandler.cpp
parentf19f813537c7aea1c20749c914e756b54a9c3cf5 (diff)
download7zip-22.00.tar.gz
7zip-22.00.tar.bz2
7zip-22.00.zip
22.0022.00
Diffstat (limited to '')
-rw-r--r--CPP/Common/NewHandler.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/CPP/Common/NewHandler.cpp b/CPP/Common/NewHandler.cpp
index 7e5b1d4..65ef41d 100644
--- a/CPP/Common/NewHandler.cpp
+++ b/CPP/Common/NewHandler.cpp
@@ -97,19 +97,33 @@ const int kDebugSize = 1000000;
97static void *a[kDebugSize]; 97static void *a[kDebugSize];
98static int index = 0; 98static int index = 0;
99 99
100static bool wasInit = false;
101static CRITICAL_SECTION cs;
102
100static int numAllocs = 0; 103static int numAllocs = 0;
101void * __cdecl operator new(size_t size) 104void * __cdecl operator new(size_t size)
102{ 105{
106 if (!wasInit)
107 {
108 InitializeCriticalSection(&cs);
109 wasInit = true;
110 }
111 EnterCriticalSection(&cs);
112
103 numAllocs++; 113 numAllocs++;
114 int loc = numAllocs;
104 void *p = HeapAlloc(GetProcessHeap(), 0, size); 115 void *p = HeapAlloc(GetProcessHeap(), 0, size);
116 /*
105 if (index < kDebugSize) 117 if (index < kDebugSize)
106 { 118 {
107 a[index] = p; 119 a[index] = p;
108 index++; 120 index++;
109 } 121 }
122 */
123 printf("Alloc %6d, size = %8u\n", loc, (unsigned)size);
124 LeaveCriticalSection(&cs);
110 if (p == 0) 125 if (p == 0)
111 throw CNewException(); 126 throw CNewException();
112 printf("Alloc %6d, size = %8u\n", numAllocs, (unsigned)size);
113 return p; 127 return p;
114} 128}
115 129
@@ -123,6 +137,7 @@ public:
123 } 137 }
124 ~CC() 138 ~CC()
125 { 139 {
140 printf("\nDestructor: %d\n", numAllocs);
126 for (int i = 0; i < kDebugSize; i++) 141 for (int i = 0; i < kDebugSize; i++)
127 if (a[i] != 0) 142 if (a[i] != 0)
128 return; 143 return;
@@ -134,6 +149,7 @@ void __cdecl operator delete(void *p)
134{ 149{
135 if (p == 0) 150 if (p == 0)
136 return; 151 return;
152 EnterCriticalSection(&cs);
137 /* 153 /*
138 for (int i = 0; i < index; i++) 154 for (int i = 0; i < index; i++)
139 if (a[i] == p) 155 if (a[i] == p)
@@ -142,6 +158,7 @@ void __cdecl operator delete(void *p)
142 HeapFree(GetProcessHeap(), 0, p); 158 HeapFree(GetProcessHeap(), 0, p);
143 numAllocs--; 159 numAllocs--;
144 printf("Free %d\n", numAllocs); 160 printf("Free %d\n", numAllocs);
161 LeaveCriticalSection(&cs);
145} 162}
146 163
147#endif 164#endif