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.

78 lines
1.4 KiB

  1. // MemDeleteQueue.cpp: implementation of the CMemDeleteQueue class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "MemDeleteQueue.h"
  5. //////////////////////////////////////////////////////////////////////
  6. // Construction/Destruction
  7. //////////////////////////////////////////////////////////////////////
  8. CMemDeleteQueue::CMemDeleteQueue()
  9. : m_DelQueue(10010), m_DelArrayQueue(100010), m_QueueSize(100000)
  10. {
  11. }
  12. CMemDeleteQueue::~CMemDeleteQueue()
  13. {
  14. Flush();
  15. }
  16. void CMemDeleteQueue::Delete(void *ptr)
  17. {
  18. // delete ptr;
  19. m_DelQueue.AddElement(ptr);
  20. if (m_DelQueue.GetNumElementsStored() >= m_QueueSize)
  21. {
  22. FlushDelQueue();
  23. }
  24. }
  25. void CMemDeleteQueue::FlushDelQueue()
  26. {
  27. for (int i=0; i<m_DelQueue.GetNumElementsStored(); i++)
  28. {
  29. delete m_DelQueue.Access()[i];
  30. }
  31. m_DelQueue.SetNumElementsStored(0);
  32. }
  33. void CMemDeleteQueue::DeleteArray(TCHAR* ptr)
  34. {
  35. // delete[] ptr;
  36. m_DelArrayQueue.AddElement(ptr);
  37. if (m_DelArrayQueue.GetNumElementsStored() >= m_QueueSize)
  38. {
  39. FlushDelArrayQueue();
  40. }
  41. }
  42. void CMemDeleteQueue::FlushDelArrayQueue()
  43. {
  44. for (int i=0; i<m_DelArrayQueue.GetNumElementsStored(); i++)
  45. {
  46. delete m_DelArrayQueue.Access()[i];
  47. }
  48. m_DelArrayQueue.SetNumElementsStored(0);
  49. }
  50. CMemDeleteQueue g_DelQueue;
  51. void CMemDeleteQueue::Flush()
  52. {
  53. FlushDelQueue();
  54. FlushDelArrayQueue();
  55. }