aboutsummaryrefslogtreecommitdiff
path: root/C/7zAlloc.c
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2021-12-27 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2022-03-18 15:35:13 +0500
commitf19f813537c7aea1c20749c914e756b54a9c3cf5 (patch)
tree816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /C/7zAlloc.c
parent98e06a519b63b81986abe76d28887f6984a7732b (diff)
download7zip-21.07.tar.gz
7zip-21.07.tar.bz2
7zip-21.07.zip
'21.07'21.07
Diffstat (limited to 'C/7zAlloc.c')
-rw-r--r--C/7zAlloc.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/C/7zAlloc.c b/C/7zAlloc.c
new file mode 100644
index 0000000..c924a52
--- /dev/null
+++ b/C/7zAlloc.c
@@ -0,0 +1,80 @@
1/* 7zAlloc.c -- Allocation functions
22017-04-03 : Igor Pavlov : Public domain */
3
4#include "Precomp.h"
5
6#include <stdlib.h>
7
8#include "7zAlloc.h"
9
10/* #define _SZ_ALLOC_DEBUG */
11/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
12
13#ifdef _SZ_ALLOC_DEBUG
14
15#ifdef _WIN32
16#include <windows.h>
17#endif
18
19#include <stdio.h>
20int g_allocCount = 0;
21int g_allocCountTemp = 0;
22
23#endif
24
25void *SzAlloc(ISzAllocPtr p, size_t size)
26{
27 UNUSED_VAR(p);
28 if (size == 0)
29 return 0;
30 #ifdef _SZ_ALLOC_DEBUG
31 fprintf(stderr, "\nAlloc %10u bytes; count = %10d", (unsigned)size, g_allocCount);
32 g_allocCount++;
33 #endif
34 return malloc(size);
35}
36
37void SzFree(ISzAllocPtr p, void *address)
38{
39 UNUSED_VAR(p);
40 #ifdef _SZ_ALLOC_DEBUG
41 if (address != 0)
42 {
43 g_allocCount--;
44 fprintf(stderr, "\nFree; count = %10d", g_allocCount);
45 }
46 #endif
47 free(address);
48}
49
50void *SzAllocTemp(ISzAllocPtr p, size_t size)
51{
52 UNUSED_VAR(p);
53 if (size == 0)
54 return 0;
55 #ifdef _SZ_ALLOC_DEBUG
56 fprintf(stderr, "\nAlloc_temp %10u bytes; count = %10d", (unsigned)size, g_allocCountTemp);
57 g_allocCountTemp++;
58 #ifdef _WIN32
59 return HeapAlloc(GetProcessHeap(), 0, size);
60 #endif
61 #endif
62 return malloc(size);
63}
64
65void SzFreeTemp(ISzAllocPtr p, void *address)
66{
67 UNUSED_VAR(p);
68 #ifdef _SZ_ALLOC_DEBUG
69 if (address != 0)
70 {
71 g_allocCountTemp--;
72 fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp);
73 }
74 #ifdef _WIN32
75 HeapFree(GetProcessHeap(), 0, address);
76 return;
77 #endif
78 #endif
79 free(address);
80}