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