1 /* Alloc.h -- Memory allocation functions 2 2023-03-04 : 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 #ifdef _WIN32 26 27 #ifdef Z7_LARGE_PAGES 28 void SetLargePageSize(void); 29 #endif 30 31 void *MidAlloc(size_t size); 32 void MidFree(void *address); 33 void *BigAlloc(size_t size); 34 void BigFree(void *address); 35 36 #else 37 38 #define MidAlloc(size) MyAlloc(size) 39 #define MidFree(address) MyFree(address) 40 #define BigAlloc(size) MyAlloc(size) 41 #define BigFree(address) MyFree(address) 42 43 #endif 44 45 extern const ISzAlloc g_Alloc; 46 47 #ifdef _WIN32 48 extern const ISzAlloc g_BigAlloc; 49 extern const ISzAlloc g_MidAlloc; 50 #else 51 #define g_BigAlloc g_AlignedAlloc 52 #define g_MidAlloc g_AlignedAlloc 53 #endif 54 55 extern const ISzAlloc g_AlignedAlloc; 56 57 58 typedef struct 59 { 60 ISzAlloc vt; 61 ISzAllocPtr baseAlloc; 62 unsigned numAlignBits; /* ((1 << numAlignBits) >= sizeof(void *)) */ 63 size_t offset; /* (offset == (k * sizeof(void *)) && offset < (1 << numAlignBits) */ 64 } CAlignOffsetAlloc; 65 66 void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p); 67 68 69 EXTERN_C_END 70 71 #endif 72