BVB Source Codes

CRYENGINE Show ParticleFixedSizeElementPool.h Source code

Return Download CRYENGINE: download ParticleFixedSizeElementPool.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   ParticleFixedSizeElementPool.h
  5. //  Version:     v1.00
  6. //  Created:     15/03/2010 by Corey.
  7. //  Compilers:   Visual Studio.NET
  8. //  Description: A fragmentation-free allocator from a fixed-size pool and which
  9. //                                                       only allocates elements of the same size.
  10. // -------------------------------------------------------------------------
  11. //  History:
  12. //
  13. ////////////////////////////////////////////////////////////////////////////
  14.  
  15. #ifndef __particlefixedsizeelementpool_h__
  16. #define __particlefixedsizeelementpool_h__
  17. #pragma once
  18.  
  19. #if !defined(_RELEASE)
  20.         #define TRACK_PARTICLE_POOL_USAGE
  21. #endif
  22.  
  23. ///////////////////////////////////////////////////////////////////////////////
  24. // thread safe pool for faster allocation/deallocation of particle container and alike objects
  25. // allocate/deallocate are only a single atomic operations on a freelist
  26. class ParticleObjectPool
  27. {
  28. public:
  29.         ParticleObjectPool();
  30.         ~ParticleObjectPool();
  31.  
  32.         void                  Init(uint32 nBytesToAllocate);
  33.  
  34.         void*                 Allocate(uint32 nSize);
  35.         void                  Deallocate(void* a_memoryToDeallocate, uint32 nSize);
  36.  
  37.         stl::SPoolMemoryUsage GetTotalMemory() const;
  38.         void                  GetMemoryUsage(ICrySizer* pSizer);
  39.  
  40.         void                  ResetUsage();
  41. private:
  42.         void                  Init4KBFreeList();
  43.  
  44.         void*                 Allocate_128Byte();
  45.         void*                 Allocate_256Byte();
  46.         void*                 Allocate_512Byte();
  47.  
  48.         void                  Deallocate_128Byte(void* pPtr);
  49.         void                  Deallocate_256Byte(void* pPtr);
  50.         void                  Deallocate_512Byte(void* pPtr);
  51.  
  52.         SLockFreeSingleLinkedListHeader m_freeList4KB;  // master freelist of 4KB blocks they are splitted into the sub lists (merged back during ResetUsage)
  53.         SLockFreeSingleLinkedListHeader m_freeList128Bytes;
  54.         SLockFreeSingleLinkedListHeader m_freeList256Bytes;
  55.         SLockFreeSingleLinkedListHeader m_freeList512Bytes;
  56.  
  57.         void*                           m_pPoolMemory;
  58.         uint32                          m_nPoolCapacity;
  59.  
  60. #if defined(TRACK_PARTICLE_POOL_USAGE)
  61.         int m_nUsedMemory;
  62.         int m_nMaxUsedMemory;
  63.         int m_nMemory128Bytes;
  64.         int m_nMemory256Bytes;
  65.         int m_nMemory512Bytes;
  66.         int m_nMemory128BytesUsed;
  67.         int m_nMemory256BytesUsed;
  68.         int m_nMemory512Bytesused;
  69. #endif
  70. };
  71.  
  72. ///////////////////////////////////////////////////////////////////////////////
  73. inline stl::SPoolMemoryUsage ParticleObjectPool::GetTotalMemory() const
  74. {
  75. #if defined(TRACK_PARTICLE_POOL_USAGE)
  76.         return stl::SPoolMemoryUsage(
  77.           (size_t)m_nPoolCapacity,
  78.           (size_t)m_nMaxUsedMemory,
  79.           (size_t)m_nUsedMemory);
  80. #else
  81.         return stl::SPoolMemoryUsage(0, 0, 0);
  82. #endif
  83. }
  84.  
  85. ///////////////////////////////////////////////////////////////////////////////
  86. inline void ParticleObjectPool::GetMemoryUsage(ICrySizer* pSizer)
  87. {
  88.         pSizer->AddObject(m_pPoolMemory, m_nPoolCapacity);
  89. }
  90.  
  91. ///////////////////////////////////////////////////////////////////////////////
  92. inline void ParticleObjectPool::ResetUsage()
  93. {
  94.         // merge all allocations back into 4KB
  95.         Init4KBFreeList();
  96. #if defined(TRACK_PARTICLE_POOL_USAGE)
  97.         m_nUsedMemory = 0;
  98.         m_nMaxUsedMemory = 0;
  99. #endif
  100. }
  101.  
  102. #endif // __fixedsizeelementpool_h__
  103.  
downloadParticleFixedSizeElementPool.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top