16 #ifdef _SZ_ALLOC_DEBUG
19 int g_allocCountMid = 0;
20 int g_allocCountBig = 0;
26 #ifdef _SZ_ALLOC_DEBUG
28 void *
p = malloc(
size);
29 fprintf(
stderr,
"\nAlloc %10d bytes, count = %10d, addr = %8X",
size, g_allocCount++, (
unsigned)
p);
38 #ifdef _SZ_ALLOC_DEBUG
40 fprintf(
stderr,
"\nFree; count = %10d, addr = %8X", --g_allocCount, (
unsigned)address);
50 #ifdef _SZ_ALLOC_DEBUG
51 fprintf(
stderr,
"\nAlloc_Mid %10d bytes; count = %10d",
size, g_allocCountMid++);
53 return VirtualAlloc(0,
size, MEM_COMMIT, PAGE_READWRITE);
57 #ifdef _SZ_ALLOC_DEBUG
59 fprintf(
stderr,
"\nFree_Mid; count = %10d", --g_allocCountMid);
63 VirtualFree(address, 0, MEM_RELEASE);
66 #ifndef MEM_LARGE_PAGES
67 #undef _7ZIP_LARGE_PAGES
70 #ifdef _7ZIP_LARGE_PAGES
71 SIZE_T g_LargePageSize = 0;
72 typedef SIZE_T(WINAPI *GetLargePageMinimumP)();
75 void SetLargePageSize() {
76 #ifdef _7ZIP_LARGE_PAGES
78 GetLargePageMinimumP largePageMinimum =
79 (GetLargePageMinimumP)GetProcAddress(GetModuleHandle(TEXT(
"kernel32.dll")),
"GetLargePageMinimum");
80 if (largePageMinimum == 0)
82 size = largePageMinimum();
85 g_LargePageSize =
size;
92 #ifdef _SZ_ALLOC_DEBUG
93 fprintf(
stderr,
"\nAlloc_Big %10d bytes; count = %10d",
size, g_allocCountBig++);
96 #ifdef _7ZIP_LARGE_PAGES
97 if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) &&
size >= (1 << 18)) {
98 void *
res = VirtualAlloc(
99 0, (
size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
104 return VirtualAlloc(0,
size, MEM_COMMIT, PAGE_READWRITE);
108 #ifdef _SZ_ALLOC_DEBUG
110 fprintf(
stderr,
"\nFree_Big; count = %10d", --g_allocCountBig);
115 VirtualFree(address, 0, MEM_RELEASE);