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.

58 lines
979 B

  1. // buffer.cpp
  2. #include <stdafx.h>
  3. CBuffer::CBuffer(UINT cbInitial)
  4. {
  5. m_pb = NULL;
  6. m_cb = 0;
  7. if (cbInitial)
  8. {
  9. m_cs.Enter();
  10. Resize(cbInitial);
  11. m_cs.Leave();
  12. }
  13. }
  14. CBuffer::~CBuffer()
  15. {
  16. RonM_ASSERT(m_cs.LockCount() == 0);
  17. if (m_pb) delete [] m_pb;
  18. }
  19. void CBuffer::Resize(UINT cbRequired)
  20. {
  21. RonM_ASSERT(m_cs.LockCount());
  22. RonM_ASSERT(cbRequired > m_cb);
  23. if (m_pb) { delete [] m_pb; m_pb = NULL; m_cb = 0; }
  24. PBYTE pb = New BYTE[cbRequired];
  25. if (!pb) return; // Failures here will become apparent
  26. // when CBufferRef::StartAddress is called.
  27. m_pb = pb;
  28. m_cb = cbRequired;
  29. }
  30. CBufferRef::CBufferRef(CBuffer &Buff, UINT cbRequired)
  31. {
  32. m_pBuff = &Buff;
  33. m_pBuff->m_cs.Enter();
  34. if (cbRequired > m_pBuff->m_cb) m_pBuff->Resize(cbRequired);
  35. }
  36. CBufferRef::~CBufferRef()
  37. {
  38. m_pBuff->m_cs.Leave();
  39. }
  40. PBYTE CBufferRef::StartAddress()
  41. {
  42. return m_pBuff->m_pb;
  43. }