git subrepo pull (merge) --force deps/libchdr
[pcsx_rearmed.git] / deps / libchdr / deps / lzma-24.05 / include / Alloc.h
1 /* Alloc.h -- Memory allocation functions
2 2024-01-22 : Igor Pavlov : Public domain */
3
4 #ifndef ZIP7_INC_ALLOC_H
5 #define ZIP7_INC_ALLOC_H
6
7 #include "7zTypes.h"
8
9 EXTERN_C_BEGIN
10
11 /*
12   MyFree(NULL)        : is allowed, as free(NULL)
13   MyAlloc(0)          : returns NULL : but malloc(0)        is allowed to return NULL or non_NULL
14   MyRealloc(NULL, 0)  : returns NULL : but realloc(NULL, 0) is allowed to return NULL or non_NULL
15 MyRealloc() is similar to realloc() for the following cases:
16   MyRealloc(non_NULL, 0)         : returns NULL and always calls MyFree(ptr)
17   MyRealloc(NULL, non_ZERO)      : returns NULL, if allocation failed
18   MyRealloc(non_NULL, non_ZERO)  : returns NULL, if reallocation failed
19 */
20
21 void *MyAlloc(size_t size);
22 void MyFree(void *address);
23 void *MyRealloc(void *address, size_t size);
24
25 void *z7_AlignedAlloc(size_t size);
26 void  z7_AlignedFree(void *p);
27
28 #ifdef _WIN32
29
30 #ifdef Z7_LARGE_PAGES
31 void SetLargePageSize(void);
32 #endif
33
34 void *MidAlloc(size_t size);
35 void MidFree(void *address);
36 void *BigAlloc(size_t size);
37 void BigFree(void *address);
38
39 /* #define Z7_BIG_ALLOC_IS_ZERO_FILLED */
40
41 #else
42
43 #define MidAlloc(size)    z7_AlignedAlloc(size)
44 #define MidFree(address)  z7_AlignedFree(address)
45 #define BigAlloc(size)    z7_AlignedAlloc(size)
46 #define BigFree(address)  z7_AlignedFree(address)
47
48 #endif
49
50 extern const ISzAlloc g_Alloc;
51
52 #ifdef _WIN32
53 extern const ISzAlloc g_BigAlloc;
54 extern const ISzAlloc g_MidAlloc;
55 #else
56 #define g_BigAlloc g_AlignedAlloc
57 #define g_MidAlloc g_AlignedAlloc
58 #endif
59
60 extern const ISzAlloc g_AlignedAlloc;
61
62
63 typedef struct
64 {
65   ISzAlloc vt;
66   ISzAllocPtr baseAlloc;
67   unsigned numAlignBits; /* ((1 << numAlignBits) >= sizeof(void *)) */
68   size_t offset;         /* (offset == (k * sizeof(void *)) && offset < (1 << numAlignBits) */
69 } CAlignOffsetAlloc;
70
71 void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p);
72
73
74 EXTERN_C_END
75
76 #endif