misc/libphysfs/lzma/C/Archive/7z/7zAlloc.c
changeset 13904 99b265e0d1d0
parent 13903 5f819b90d479
child 13905 b172a5d40eee
equal deleted inserted replaced
13903:5f819b90d479 13904:99b265e0d1d0
     1 /* 7zAlloc.c */
       
     2 
       
     3 #include <stdlib.h>
       
     4 #include "7zAlloc.h"
       
     5 
       
     6 /* #define _SZ_ALLOC_DEBUG */
       
     7 /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
       
     8 
       
     9 #ifdef _SZ_ALLOC_DEBUG
       
    10 
       
    11 #ifdef _WIN32
       
    12 #include <windows.h>
       
    13 #endif
       
    14 #include <stdio.h>
       
    15 int g_allocCount = 0;
       
    16 int g_allocCountTemp = 0;
       
    17 #endif
       
    18 
       
    19 void *SzAlloc(size_t size)
       
    20 {
       
    21   if (size == 0)
       
    22     return 0;
       
    23   #ifdef _SZ_ALLOC_DEBUG
       
    24   fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount);
       
    25   g_allocCount++;
       
    26   #endif
       
    27   return malloc(size);
       
    28 }
       
    29 
       
    30 void SzFree(void *address)
       
    31 {
       
    32   #ifdef _SZ_ALLOC_DEBUG
       
    33   if (address != 0)
       
    34   {
       
    35     g_allocCount--;
       
    36     fprintf(stderr, "\nFree; count = %10d", g_allocCount);
       
    37   }
       
    38   #endif
       
    39   free(address);
       
    40 }
       
    41 
       
    42 void *SzAllocTemp(size_t size)
       
    43 {
       
    44   if (size == 0)
       
    45     return 0;
       
    46   #ifdef _SZ_ALLOC_DEBUG
       
    47   fprintf(stderr, "\nAlloc_temp %10d bytes;  count = %10d", size, g_allocCountTemp);
       
    48   g_allocCountTemp++;
       
    49   #ifdef _WIN32
       
    50   return HeapAlloc(GetProcessHeap(), 0, size);
       
    51   #endif
       
    52   #endif
       
    53   return malloc(size);
       
    54 }
       
    55 
       
    56 void SzFreeTemp(void *address)
       
    57 {
       
    58   #ifdef _SZ_ALLOC_DEBUG
       
    59   if (address != 0)
       
    60   {
       
    61     g_allocCountTemp--;
       
    62     fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp);
       
    63   }
       
    64   #ifdef _WIN32
       
    65   HeapFree(GetProcessHeap(), 0, address);
       
    66   return;
       
    67   #endif
       
    68   #endif
       
    69   free(address);
       
    70 }