Alloc.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. /***************************************************************************
  7. NoReleaseAllocator - allocator that never releases until it is destroyed
  8. ***************************************************************************/
  9. class NoReleaseAllocator
  10. {
  11. public:
  12. NoReleaseAllocator(DECLSPEC_GUARD_OVERFLOW int32 cbFirst = 256, DECLSPEC_GUARD_OVERFLOW int32 cbMax = 0x4000 /*16K*/);
  13. ~NoReleaseAllocator(void) { FreeAll(); }
  14. void *Alloc(DECLSPEC_GUARD_OVERFLOW int32 cb);
  15. void FreeAll();
  16. void Clear() { FreeAll(); }
  17. private:
  18. struct NraBlock
  19. {
  20. NraBlock * pblkNext;
  21. // ... DATA ...
  22. };
  23. NraBlock * m_pblkList;
  24. int32 m_ibCur;
  25. int32 m_ibMax;
  26. int32 m_cbMinBlock;
  27. int32 m_cbMaxBlock;
  28. #if DEBUG
  29. int32 m_cbTotRequested; // total bytes requested
  30. int32 m_cbTotAlloced; // total bytes allocated including headers
  31. int32 m_cblk; // number of blocks including big blocks
  32. int32 m_cpvBig; // each generates its own big block
  33. int32 m_cpvSmall; // put in a common block
  34. #endif //DEBUG
  35. };