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.

50 lines
1.1 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. STACK.CPP
  5. Abstract:
  6. CStack
  7. History:
  8. 26-Apr-96 a-raymcc Created.
  9. --*/
  10. #include "precomp.h"
  11. #include <stdio.h>
  12. #include "Arena.h"
  13. #include "stack.h"
  14. #include "corex.h"
  15. CStack::CStack(DWORD dwInitSize, DWORD dwGrowBy)
  16. {
  17. m_dwSize = dwInitSize;
  18. m_dwGrowBy = dwGrowBy * sizeof(DWORD);
  19. m_dwStackPtr = (DWORD) -1;
  20. m_pData = (DWORD *)CWin32DefaultArena::WbemMemAlloc(m_dwSize * sizeof(DWORD));
  21. if (m_pData == 0)
  22. throw CX_MemoryException();
  23. ZeroMemory(m_pData, m_dwSize * sizeof(DWORD)); // SEC:REVIEWED 2002-03-22 : OK
  24. }
  25. void CStack::Push(DWORD dwValue)
  26. {
  27. if ( m_dwStackPtr + 1 == m_dwSize) {
  28. DWORD * pTmp = (DWORD *)CWin32DefaultArena::WbemMemReAlloc(m_pData, (m_dwSize+m_dwGrowBy) * sizeof(DWORD));
  29. if (0 == pTmp) throw CX_MemoryException();
  30. m_dwSize += m_dwGrowBy;
  31. m_pData = pTmp;
  32. }
  33. m_pData[++m_dwStackPtr] = dwValue;
  34. }
  35. CStack::~CStack()
  36. {
  37. CWin32DefaultArena::WbemMemFree(m_pData);
  38. }