Annotation of elwix/tools/oldlzma/SRC/Common/Alloc.cpp, revision 1.1
1.1 ! misho 1: // Common/Alloc.cpp
! 2:
! 3: #include "StdAfx.h"
! 4:
! 5: #ifdef _WIN32
! 6: #include "MyWindows.h"
! 7: #else
! 8: #include <stdlib.h>
! 9: #endif
! 10:
! 11: #include "Alloc.h"
! 12:
! 13: /* #define _SZ_ALLOC_DEBUG */
! 14: /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
! 15: #ifdef _SZ_ALLOC_DEBUG
! 16: #include <stdio.h>
! 17: int g_allocCount = 0;
! 18: int g_allocCountBig = 0;
! 19: #endif
! 20:
! 21: void *MyAlloc(size_t size)
! 22: {
! 23: #ifdef _SZ_ALLOC_DEBUG
! 24: fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount++);
! 25: #endif
! 26:
! 27: return ::malloc(size);
! 28: }
! 29:
! 30: void MyFree(void *address)
! 31: {
! 32: #ifdef _SZ_ALLOC_DEBUG
! 33: if (address != 0)
! 34: fprintf(stderr, "\nFree; count = %10d", --g_allocCount);
! 35: #endif
! 36:
! 37: ::free(address);
! 38: }
! 39:
! 40: void *BigAlloc(size_t size)
! 41: {
! 42: #ifdef _SZ_ALLOC_DEBUG
! 43: fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++);
! 44: #endif
! 45:
! 46: #ifdef _WIN32
! 47: return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
! 48: #else
! 49: return ::malloc(size);
! 50: #endif
! 51: }
! 52:
! 53: void BigFree(void *address)
! 54: {
! 55: #ifdef _SZ_ALLOC_DEBUG
! 56: if (address != 0)
! 57: fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
! 58: #endif
! 59:
! 60: if (address == 0)
! 61: return;
! 62: #ifdef _WIN32
! 63: ::VirtualFree(address, 0, MEM_RELEASE);
! 64: #else
! 65: ::free(address);
! 66: #endif
! 67: }
! 68:
! 69: /*
! 70: void *BigAllocE(size_t size)
! 71: {
! 72: void *res = BigAlloc(size);
! 73: #ifndef _NO_EXCEPTIONS
! 74: if (res == 0)
! 75: throw CNewException();
! 76: #endif
! 77: return res;
! 78: }
! 79: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>