OLD | NEW |
| (Empty) |
1 /* 7zAlloc.c -- Allocation functions | |
2 2008-10-04 : Igor Pavlov : Public domain */ | |
3 | |
4 #include <stdlib.h> | |
5 #include "7zAlloc.h" | |
6 | |
7 /* #define _SZ_ALLOC_DEBUG */ | |
8 /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ | |
9 | |
10 #ifdef _SZ_ALLOC_DEBUG | |
11 | |
12 #ifdef _WIN32 | |
13 #include <windows.h> | |
14 #endif | |
15 | |
16 #include <stdio.h> | |
17 int g_allocCount = 0; | |
18 int g_allocCountTemp = 0; | |
19 | |
20 #endif | |
21 | |
22 void *SzAlloc(void *p, size_t size) | |
23 { | |
24 p = p; | |
25 if (size == 0) | |
26 return 0; | |
27 #ifdef _SZ_ALLOC_DEBUG | |
28 fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount); | |
29 g_allocCount++; | |
30 #endif | |
31 return malloc(size); | |
32 } | |
33 | |
34 void SzFree(void *p, void *address) | |
35 { | |
36 p = p; | |
37 #ifdef _SZ_ALLOC_DEBUG | |
38 if (address != 0) | |
39 { | |
40 g_allocCount--; | |
41 fprintf(stderr, "\nFree; count = %10d", g_allocCount); | |
42 } | |
43 #endif | |
44 free(address); | |
45 } | |
46 | |
47 void *SzAllocTemp(void *p, size_t size) | |
48 { | |
49 p = p; | |
50 if (size == 0) | |
51 return 0; | |
52 #ifdef _SZ_ALLOC_DEBUG | |
53 fprintf(stderr, "\nAlloc_temp %10d bytes; count = %10d", size, g_allocCountTe
mp); | |
54 g_allocCountTemp++; | |
55 #ifdef _WIN32 | |
56 return HeapAlloc(GetProcessHeap(), 0, size); | |
57 #endif | |
58 #endif | |
59 return malloc(size); | |
60 } | |
61 | |
62 void SzFreeTemp(void *p, void *address) | |
63 { | |
64 p = p; | |
65 #ifdef _SZ_ALLOC_DEBUG | |
66 if (address != 0) | |
67 { | |
68 g_allocCountTemp--; | |
69 fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp); | |
70 } | |
71 #ifdef _WIN32 | |
72 HeapFree(GetProcessHeap(), 0, address); | |
73 return; | |
74 #endif | |
75 #endif | |
76 free(address); | |
77 } | |
OLD | NEW |