Counter Strike : Global Offensive Source Code
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.

93 lines
2.6 KiB

  1. //=========== (C) Copyright 2000 Valve, L.L.C. All rights reserved. ===========
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // Purpose:
  9. //
  10. // $Workfile: $
  11. // $Date: $
  12. //
  13. //-----------------------------------------------------------------------------
  14. // $Log: $
  15. //
  16. // $NoKeywords: $
  17. //=============================================================================
  18. #ifndef TSMULTIMEMPOOL_H
  19. #define TSMULTIMEMPOOL_H
  20. #ifdef _WIN32
  21. #pragma once
  22. #endif
  23. #include "tier1/utlmap.h"
  24. #include "tier1/mempool.h"
  25. #include "tier1/tsmempool.h"
  26. //-----------------------------------------------------------------------------
  27. // Purpose: A container of a range of mem pool sizes (for network buffers for example)
  28. // and a raw alloc capability (for sizes greater than any contained mem pool).
  29. //-----------------------------------------------------------------------------
  30. class CThreadSafeMultiMemoryPool
  31. {
  32. public:
  33. struct MemPoolConfig_t
  34. {
  35. uint32 m_cubBlockSize;
  36. uint32 m_cubDefaultPoolSize;
  37. };
  38. CThreadSafeMultiMemoryPool( const MemPoolConfig_t *pnBlock, int cnMemPoolConfig, int nGrowMode = CUtlMemoryPool::GROW_FAST );
  39. ~CThreadSafeMultiMemoryPool();
  40. // Allocate a block of at least nAllocSize bytes
  41. void* Alloc( uint32 cubAlloc );
  42. // Free a previously alloc'd block
  43. void Free(void *pvMem);
  44. // ReAllocate a previously allocated block to a new size
  45. void* ReAlloc( void *pvMem, uint32 cubAlloc );
  46. // Frees everything
  47. void Clear();
  48. // alloc size for this bit of alloc'd memory
  49. int CubAllocSize( void *pvMem );
  50. // prints details about our contained memory
  51. void PrintStats();
  52. // total number of alloc'd elements
  53. int Count();
  54. // Return the total size in MB allocated for this pool
  55. int CMBPoolSize() const;
  56. // Return the amount of memory in use
  57. int CMBPoolSizeInUse() const;
  58. private:
  59. struct MemPoolRecord_t
  60. {
  61. CThreadSafeMemoryPool *m_pMemPool;
  62. uint32 m_nBlockSize;
  63. };
  64. CUtlVector<MemPoolRecord_t> m_VecMemPool; // stores our list of mem pools
  65. uint32 m_nBlockSizeMax;
  66. CUtlVector<MemPoolRecord_t *> m_VecMemPoolLookup; // quick lookup table of mempools
  67. struct RawAllocation_t
  68. {
  69. void *m_pvMem;
  70. uint32 m_nBlockSize;
  71. };
  72. CUtlMap<void *,RawAllocation_t,int> m_MapRawAllocation; // stores our list of raw alloc'd mem
  73. CThreadFastMutex m_mutexRawAllocations;
  74. uint32 m_cubReallocedTotal;
  75. };
  76. #endif // TSMULTIMEMPOOL_H