1 /* Alloc.h -- Memory allocation functions
2 2024-01-22 : Igor Pavlov : Public domain */
4 #ifndef ZIP7_INC_ALLOC_H
5 #define ZIP7_INC_ALLOC_H
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
21 void *MyAlloc(size_t size);
22 void MyFree(void *address);
23 void *MyRealloc(void *address, size_t size);
25 void *z7_AlignedAlloc(size_t size);
26 void z7_AlignedFree(void *p);
31 void SetLargePageSize(void);
34 void *MidAlloc(size_t size);
35 void MidFree(void *address);
36 void *BigAlloc(size_t size);
37 void BigFree(void *address);
39 /* #define Z7_BIG_ALLOC_IS_ZERO_FILLED */
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)
50 extern const ISzAlloc g_Alloc;
53 extern const ISzAlloc g_BigAlloc;
54 extern const ISzAlloc g_MidAlloc;
56 #define g_BigAlloc g_AlignedAlloc
57 #define g_MidAlloc g_AlignedAlloc
60 extern const ISzAlloc g_AlignedAlloc;
66 ISzAllocPtr baseAlloc;
67 unsigned numAlignBits; /* ((1 << numAlignBits) >= sizeof(void *)) */
68 size_t offset; /* (offset == (k * sizeof(void *)) && offset < (1 << numAlignBits) */
71 void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p);