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