ALLOC.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef ALLOC_H
  2. #define ALLOC_H
  3. #include "TASSERT.h"
  4. #if defined __cplusplus
  5. #include <new>
  6. #endif
  7. #if !defined __cplusplus
  8. #define ___23(N,___4236,str) (___4236 *)malloc((N)*sizeof(___4236))
  9. #define ALLOC_ITEM(___4236,str) (___4236 *)malloc(sizeof(___4236))
  10. #ifdef _DEBUG
  11. #define ___1530(X,str) do { free((void *)(X)); *((void **)&(X)) = (void *)0xFFFF; } while (0)
  12. #define ___1531(X,str) do { free((void *)(X)); *((void **)&(X)) = (void *)0xFFFF; } while (0)
  13. #else
  14. #define ___1530(X,str) free((void *)(X))
  15. #define ___1531(X,str) free((void *)(X))
  16. #endif
  17. #else
  18. #ifdef TRACK_MEMORY_USAGE
  19. extern void ___1936(void); extern void ___491(void); extern void ___4207(size_t size); extern void ___4209(size_t size); extern void ___4208(void); extern void ___4210(void); extern void ___1758(size_t* ___2407, size_t* ___2406, size_t* ___2408, size_t* ___2409);
  20. #endif
  21. #if defined MSWIN && defined _DEBUG && defined TRACK_MEMORY_USAGE
  22. template <typename T> inline T *nonExceptionNew(size_t ___2812, const char* ___1394, int lineNumber) { REQUIRE(___2812 > 0); REQUIRE(VALID_REF(___1394)); REQUIRE(lineNumber > 0); T* ___3358 = NULL; try {
  23. #ifdef DEBUG_NEW
  24. #ifdef new
  25. #undef new
  26. #define USING_DEBUG_NEW
  27. #endif
  28. ___3358 = new(___1394, lineNumber) T[___2812];
  29. #ifdef USING_DEBUG_NEW
  30. #undef USING_DEBUG_NEW
  31. #endif
  32. #else
  33. ___3358 = new T[___2812];
  34. #endif
  35. } catch (std::bad_alloc&) { ___3358 = NULL; }
  36. #ifdef TRACK_MEMORY_USAGE
  37. if (___3358 != NULL) {
  38. #ifdef MSWIN
  39. ___4207(_msize(___3358));
  40. #else
  41. ___4207(malloc_usable_size(___3358));
  42. #endif
  43. }
  44. #endif
  45. ENSURE(VALID_REF_OR_NULL(___3358)); return ___3358; }
  46. #define ___23(N,___4236,str) nonExceptionNew<___4236>((N),__FILE__,__LINE__)
  47. #else
  48. template <typename T> inline T *nonExceptionNew(size_t ___2812) { REQUIRE(___2812 > 0); T *___3358 = NULL; try { ___3358 = new T[___2812]; } catch (std::bad_alloc&) { ___3358 = NULL; }
  49. #ifdef TRACK_MEMORY_USAGE
  50. if (___3358 != NULL) {
  51. #ifdef MSWIN
  52. ___4207(_msize(___3358));
  53. #else
  54. ___4207(malloc_usable_size(___3358));
  55. #endif
  56. }
  57. #endif
  58. return ___3358; }
  59. #define ___23(N,___4236,str) nonExceptionNew<___4236>((N))
  60. #endif
  61. #define ALLOC_ITEM(___4236,str) ___23(1,___4236,str)
  62. template <typename T> inline void nonExceptionDelete(T* &___3251) { REQUIRE(VALID_REF(___3251));
  63. #if defined TRACK_MEMORY_USAGE
  64. { if (___3251 != NULL) {
  65. #ifdef MSWIN
  66. ___4209(_msize(___3251));
  67. #else
  68. ___4209(malloc_usable_size(___3251));
  69. #endif
  70. } }
  71. #endif
  72. delete [] ___3251;
  73. #if !defined NO_ASSERTS
  74. ___3251 = (T*)(void*)0xFFFF;
  75. #endif
  76. } template <typename T> inline void nonExceptionDelete(T* const& ___3251) { nonExceptionDelete(const_cast<T*&>(___3251)); }
  77. #define ___1530(___3251,str) nonExceptionDelete((___3251))
  78. #define ___1531(___3251,str) ___1530(___3251,str)
  79. #endif
  80. struct ___956 { template<typename T> void operator()(T*& object) { delete object; object = NULL; } };
  81. #endif