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