Leaked source code of windows server 2003
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.

92 lines
1.7 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. //
  3. // memory management stuff
  4. //
  5. // 22-Nov-1999 sburns (refactored)
  6. //
  7. // This file is #include'd from mem.cpp
  8. // DO NOT include in the sources file list
  9. //
  10. // this is the retail version:
  11. #ifdef DBG
  12. #error This file must NOT be compiled with the DBG symbol defined
  13. #endif
  14. //
  15. // Retail build only
  16. //
  17. void
  18. Burnslib::Heap::Initialize()
  19. {
  20. // we do not make available instrumented heap in retail builds, so there
  21. // is nothing to do here.
  22. }
  23. void*
  24. Burnslib::Heap::OperatorNew(
  25. size_t size,
  26. const char* /* file */ ,
  27. int /* line */ )
  28. throw (std::bad_alloc)
  29. {
  30. void* ptr = 0;
  31. for (;;)
  32. {
  33. // NOTE: if some other user of the CRT has used _set_new_mode or
  34. // _CrtSetAllocHook, then they may circumvent our careful arrangement
  35. // and hose us. The really sad part is that the only way to prevent
  36. // that problem is for us to not use any CRT heap functions.
  37. ptr = malloc(size);
  38. if (ptr)
  39. {
  40. break;
  41. }
  42. // the allocation failed. Give the user the opportunity to try to
  43. // free some, or throw an exception.
  44. if (DoLowMemoryDialog() == IDRETRY)
  45. {
  46. continue;
  47. }
  48. ::OutputDebugString(RUNTIME_NAME);
  49. ::OutputDebugString(
  50. L" Burnslib::Heap::OperatorNew: user opted to throw bad_alloc\n");
  51. throw nomem;
  52. }
  53. return ptr;
  54. }
  55. void
  56. Burnslib::Heap::OperatorDelete(void* ptr)
  57. throw ()
  58. {
  59. free(ptr);
  60. }
  61. void
  62. Burnslib::Heap::DumpMemoryLeaks()
  63. {
  64. // does nothing in the retail (free) build.
  65. }