diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /engine/zone.h | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'engine/zone.h')
| -rw-r--r-- | engine/zone.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/engine/zone.h b/engine/zone.h new file mode 100644 index 0000000..be0b9c3 --- /dev/null +++ b/engine/zone.h @@ -0,0 +1,84 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +#ifndef ZONE_H +#define ZONE_H +#pragma once + +#include "tier0/dbg.h" + +void Memory_Init (void); +void Memory_Shutdown( void ); + +void *Hunk_Alloc(int size, bool bClear = true ); +void *Hunk_AllocName (int size, const char *name, bool bClear = true ); + +int Hunk_LowMark (void); +void Hunk_FreeToLowMark (int mark); + +void Hunk_Check (void); + +int Hunk_MallocSize(); +int Hunk_Size(); + +void Hunk_Print(); + +template< typename T > +class CHunkMemory +{ +public: + // constructor, destructor + CHunkMemory( int nGrowSize = 0, int nInitSize = 0 ) { m_pMemory = NULL; m_nAllocated = 0; if ( nInitSize ) Grow( nInitSize ); } + CHunkMemory( T* pMemory, int numElements ) { Assert( 0 ); } + + // Can we use this index? + bool IsIdxValid( int i ) const { return (i >= 0) && (i < m_nAllocated); } + + // Gets the base address + T* Base() { return (T*)m_pMemory; } + const T* Base() const { return (T*)m_pMemory; } + + // element access + T& operator[]( int i ) { Assert( IsIdxValid(i) ); return Base()[i]; } + const T& operator[]( int i ) const { Assert( IsIdxValid(i) ); return Base()[i]; } + T& Element( int i ) { Assert( IsIdxValid(i) ); return Base()[i]; } + const T& Element( int i ) const { Assert( IsIdxValid(i) ); return Base()[i]; } + + // Attaches the buffer to external memory.... + void SetExternalBuffer( T* pMemory, int numElements ) { Assert( 0 ); } + + // Size + int NumAllocated() const { return m_nAllocated; } + int Count() const { return m_nAllocated; } + + // Grows the memory, so that at least allocated + num elements are allocated + void Grow( int num = 1 ) { Assert( !m_nAllocated ); m_pMemory = (T *)Hunk_Alloc( num * sizeof(T), false ); m_nAllocated = num; } + + // Makes sure we've got at least this much memory + void EnsureCapacity( int num ) { Assert( num <= m_nAllocated ); } + + // Memory deallocation + void Purge() { m_nAllocated = 0; } + + // Purge all but the given number of elements (NOT IMPLEMENTED IN ) + void Purge( int numElements ) { Assert( 0 ); } + + // is the memory externally allocated? + bool IsExternallyAllocated() const { return false; } + + // Set the size by which the memory grows + void SetGrowSize( int size ) {} + +private: + T *m_pMemory; + int m_nAllocated; +}; + + +#endif // ZONE_H + + |