Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.4 KiB

  1. /* 7zAlloc.c -- Allocation functions
  2. 2010-10-29 : Igor Pavlov : Public domain */
  3. #include "Precomp.h"
  4. #include "7zAlloc.h"
  5. /* #define _SZ_ALLOC_DEBUG */
  6. /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
  7. #ifdef _SZ_ALLOC_DEBUG
  8. #ifdef _WIN32
  9. #include <windows.h>
  10. #endif
  11. #include <stdio.h>
  12. int g_allocCount = 0;
  13. int g_allocCountTemp = 0;
  14. #endif
  15. void *SzAlloc(void *p, size_t size)
  16. {
  17. p = p;
  18. if (size == 0)
  19. return 0;
  20. #ifdef _SZ_ALLOC_DEBUG
  21. fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount);
  22. g_allocCount++;
  23. #endif
  24. return malloc(size);
  25. }
  26. void SzFree(void *p, void *address)
  27. {
  28. p = p;
  29. #ifdef _SZ_ALLOC_DEBUG
  30. if (address != 0)
  31. {
  32. g_allocCount--;
  33. fprintf(stderr, "\nFree; count = %10d", g_allocCount);
  34. }
  35. #endif
  36. free(address);
  37. }
  38. void *SzAllocTemp(void *p, size_t size)
  39. {
  40. p = p;
  41. if (size == 0)
  42. return 0;
  43. #ifdef _SZ_ALLOC_DEBUG
  44. fprintf(stderr, "\nAlloc_temp %10d bytes; count = %10d", size, g_allocCountTemp);
  45. g_allocCountTemp++;
  46. #ifdef _WIN32
  47. return HeapAlloc(GetProcessHeap(), 0, size);
  48. #endif
  49. #endif
  50. return malloc(size);
  51. }
  52. void SzFreeTemp(void *p, void *address)
  53. {
  54. p = p;
  55. #ifdef _SZ_ALLOC_DEBUG
  56. if (address != 0)
  57. {
  58. g_allocCountTemp--;
  59. fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp);
  60. }
  61. #ifdef _WIN32
  62. HeapFree(GetProcessHeap(), 0, address);
  63. return;
  64. #endif
  65. #endif
  66. free(address);
  67. }