SpComm.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef _SP_COMM_H__
  2. #define _SP_COMM_H__
  3. #define _CRTDBG_MAP_ALLOC
  4. #include <stdlib.h>
  5. #ifdef RVC_OS_WIN
  6. #include <crtdbg.h>
  7. #endif //RVC_OS_WIN
  8. #include <cstring>
  9. #include <iostream>
  10. #include <sstream>
  11. #include "SpBase.h"
  12. namespace SP
  13. {
  14. /** Leak Detector*/
  15. namespace Perf
  16. {
  17. struct LeakDetector
  18. {
  19. LeakDetector()
  20. {
  21. #if defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  22. int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
  23. flag |= _CRTDBG_LEAK_CHECK_DF;
  24. flag |= _CRTDBG_ALLOC_MEM_DF;
  25. _CrtSetDbgFlag(flag);
  26. #endif //defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  27. }
  28. ~LeakDetector()
  29. {
  30. }
  31. };
  32. struct LineLeakDetector
  33. {
  34. LineLeakDetector() {
  35. #if defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  36. _CrtMemCheckpoint(&s1);
  37. #endif //defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  38. }
  39. ~LineLeakDetector()
  40. {
  41. #if defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  42. _CrtMemCheckpoint(&s2);
  43. if (_CrtMemDifference(&s3, &s1, &s2))
  44. _CrtMemDumpStatistics(&s3);
  45. //_CrtDumpMemoryLeaks();
  46. #endif //defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  47. }
  48. #if defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  49. _CrtMemState s1, s2, s3;
  50. #endif //defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  51. };
  52. }
  53. }
  54. #ifndef ASSERT
  55. #include <assert.h>
  56. #define ASSERT assert
  57. #endif
  58. #endif // _SP_COMM_H__