Source code of Windows XP (NT5)
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.

99 lines
2.2 KiB

  1. // Copyright (C) 1993-1997 Microsoft Corporation. All rights reserved.
  2. #if _MSC_VER > 1000
  3. #pragma once
  4. #endif
  5. #ifndef LCMEM_H
  6. #define LCMEM_H
  7. #define THIS_FILE __FILE__
  8. #define CHECK_AND_FREE(x) if (x) { lcFree(x) ; x = NULL ; }
  9. // map all memory functions to CRT except for HHW which
  10. // uses the exported functions from HHA
  11. #ifdef HHW
  12. // exported by HHA
  13. void* STDCALL rmalloc(int cb);
  14. void* STDCALL rcalloc(int cb);
  15. void STDCALL rfree(void* pv);
  16. void* STDCALL rrealloc(void* pv, int cb);
  17. void STDCALL rclearfree(void** pv);
  18. int STDCALL lcSize(void* pv);
  19. // map the lc functions to those exported by HHA
  20. #define lcMalloc(cb) rmalloc(cb)
  21. #define lcCalloc(cb) rcalloc(cb)
  22. #define lcFree(pv) rfree((void*) (pv))
  23. #define lcClearFree(pv) rclearfree((void**) (pv))
  24. #define lcReAlloc(pv, cb) rrealloc((void*) (pv), cb)
  25. #else // HHA and HHCTRL
  26. #include <malloc.h>
  27. #include <crtdbg.h>
  28. #define lcMalloc(cb) malloc(cb)
  29. __inline void* lcCalloc(int cb) { void* pv = lcMalloc(cb); ZeroMemory(pv, cb); return pv; }
  30. #define lcFree(pv) free((void*) pv)
  31. #define lcClearFree(pv) { lcFree(*pv); *pv = NULL; }
  32. #define lcReAlloc(pv, cb) realloc(pv, cb)
  33. #define lcSize(pv) _msize(pv)
  34. #endif // HHW
  35. // common to all
  36. #define lcHeapCheck()
  37. PSTR lcStrDup(PCSTR psz);
  38. PWSTR lcStrDupW(PCWSTR psz);
  39. #ifdef HHCTRL
  40. void OnReportMemoryUsage();
  41. #endif
  42. class CMem
  43. {
  44. public:
  45. PBYTE pb;
  46. #ifndef HHCTRL
  47. PSTR psz; // identical to pb, used for casting convenience
  48. #endif
  49. CMem(void);
  50. CMem(int size);
  51. ~CMem(void) {
  52. if(pb)
  53. lcFree(pb);
  54. }
  55. #ifndef HHCTRL
  56. int size(void);
  57. void resize(int cb);
  58. #endif
  59. void ReAlloc(int cbNewSize) {
  60. pb = (PBYTE) lcReAlloc(pb, cbNewSize);
  61. #ifndef HHCTRL
  62. psz = (PSTR) pb;
  63. #endif
  64. }
  65. void Malloc(int cb) {
  66. _ASSERT(!pb);
  67. pb = (PBYTE) lcMalloc(cb);
  68. #ifndef HHCTRL
  69. psz = (PSTR) pb;
  70. #endif
  71. }
  72. operator void*() { return (void*) pb; };
  73. operator PCSTR() { return (PCSTR) pb; };
  74. operator PSTR() { return (PSTR) pb; };
  75. operator PBYTE() { return pb; };
  76. operator LPWSTR() { return (LPWSTR) pb; };
  77. };
  78. #endif // LCMEM_H