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.

64 lines
1.4 KiB

  1. /***************************************************************************\
  2. *
  3. * File: AllocPool.h
  4. *
  5. * Description:
  6. * AllocPool defines a lightweight class used to pool memory allocations in
  7. * a LIFO stack. This class has been designed work specifically well with
  8. * RockAll.
  9. *
  10. *
  11. * History:
  12. * 1/28/2000: JStall: Created
  13. *
  14. * Copyright (C) 2000 by Microsoft Corporation. All rights reserved.
  15. *
  16. \***************************************************************************/
  17. #if !defined(BASE__AllocPool_h__INCLUDED)
  18. #define BASE__AllocPool_h__INCLUDED
  19. #pragma once
  20. #include "SimpleHeap.h"
  21. #include "Locks.h"
  22. template <class T, int cbBlock = 64, class heap = ContextHeap>
  23. class AllocPoolNL
  24. {
  25. // Construction
  26. public:
  27. inline AllocPoolNL();
  28. inline ~AllocPoolNL();
  29. inline void Destroy();
  30. // Operations
  31. public:
  32. inline T * New();
  33. inline void Delete(T * pvMem);
  34. inline BOOL IsEmpty() const;
  35. // Data
  36. protected:
  37. T * m_rgItems[cbBlock * 2];
  38. int m_nTop;
  39. };
  40. template <class T, int cbBlock = 64>
  41. class AllocPool : public AllocPoolNL<T, cbBlock, ProcessHeap>
  42. {
  43. // Operations
  44. public:
  45. inline T * New();
  46. inline void Delete(T * pvMem);
  47. // Data
  48. protected:
  49. CritLock m_lock;
  50. };
  51. #include "AllocPool.inl"
  52. #endif // BASE__AllocPool_h__INCLUDED