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.

43 lines
1.6 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: CPoolMac.h
  5. //
  6. // Description: Definitions of CPool Helper Macros. Moved from transmem.h to
  7. // make it easier to use CPool without Exchmem (for COM dlls).
  8. //
  9. // Author: mikeswa
  10. //
  11. // Copyright (C) 1997 Microsoft Corporation
  12. //
  13. //-----------------------------------------------------------------------------
  14. #ifndef _CPOOLMAC_H_
  15. #define _CPOOLMAC_H_
  16. #include <cpool.h>
  17. #include <dbgtrace.h>
  18. //If you would rather use Exchmem (or the default new & delete),
  19. //then define OVERRIDE_CPOOL
  20. #ifndef OVERRIDE_CPOOL
  21. //Use after "public:" in class definition
  22. #define DEFINE_CPOOL_MEMBERS \
  23. static CPool m_MyClassPool; \
  24. inline void *operator new(size_t size) {return m_MyClassPool.Alloc();}; \
  25. inline void operator delete(void *p, size_t size) {m_MyClassPool.Free(p);};
  26. //Use at top of classes CPP file
  27. #define DECLARE_CPOOL_STATIC(CMyClass) \
  28. CPool CMyClass::m_MyClassPool;
  29. //Use in "main" before any classes are allocated
  30. #define F_INIT_CPOOL(CMyClass, NumPreAlloc) \
  31. CMyClass::m_MyClassPool.ReserveMemory(NumPreAlloc, sizeof(CMyClass))
  32. #define RELEASE_CPOOL(CMyClass) \
  33. {_ASSERT(CMyClass::m_MyClassPool.GetAllocCount() == 0);CMyClass::m_MyClassPool.ReleaseMemory();}
  34. #else //use exchmem to track allocations
  35. #define DEFINE_CPOOL_MEMBERS
  36. #define F_INIT_CPOOL(CMyClass, NumPreAlloc) true
  37. #define RELEASE_CPOOL(CMyClass)
  38. #endif //OVERRIDE_CPOOL
  39. #endif //_CPOOLMAC_H_