Fix bugs and many compiler warnings

* Promoted size types in CUtlBuffer to int64.
* Fixed bug where CUtlBuffer::GetPtr returns a 64bit pointer that was promoted from a 32bit integral type.
* Use int64/size_t for anything strlen, pointer subtraction, etc..
* Removed invalid structure alignment declarations.
This commit is contained in:
Kawe Mazidjatari 2022-11-24 15:41:52 +01:00
parent 1f10bb1643
commit 4ba88963ff
14 changed files with 184 additions and 180 deletions

View File

@ -67,7 +67,7 @@ bool CBaseFileSystem::VCheckDisk(const char* pszFilePath)
std::string svFilePath = ConvertToWinPath(pszFilePath);
if (svFilePath.find("\\\*\\") != string::npos)
if (svFilePath.find("\\*\\") != string::npos)
{
// Erase '//*/'.
svFilePath.erase(0, 4);

View File

@ -97,7 +97,7 @@ CMemory CMemory::FindPattern(const string& svPattern, const Direction searchDire
// If either the current byte equals to the byte in our pattern or our current byte in the pattern is a wildcard
// our if clause will be false.
uint8_t currentByte = *(pScanBytes + nMemOffset + j);
_mm_prefetch(reinterpret_cast<const char*>(currentByte + nMemOffset + 64), _MM_HINT_T0); // precache some data in L1.
_mm_prefetch(reinterpret_cast<const CHAR*>(static_cast<int64>(currentByte + nMemOffset + 64)), _MM_HINT_T0); // precache some data in L1.
if (currentByte != bytesInfo.second[j] && bytesInfo.second[j] != -1)
{
bFound = false;
@ -144,7 +144,7 @@ CMemory CMemory::FindPatternSelf(const string& svPattern, const Direction search
// If either the current byte equals to the byte in our pattern or our current byte in the pattern is a wildcard
// our if clause will be false.
uint8_t currentByte = *(pScanBytes + nMemOffset + j);
_mm_prefetch(reinterpret_cast<const char*>(currentByte + nMemOffset + 64), _MM_HINT_T0); // precache some data in L1.
_mm_prefetch(reinterpret_cast<const CHAR*>(static_cast<int64>(currentByte + nMemOffset + 64)), _MM_HINT_T0); // precache some data in L1.
if (currentByte != bytesInfo.second[j] && bytesInfo.second[j] != -1)
{
bFound = false;

View File

@ -69,7 +69,7 @@ CMemory CModule::FindPatternSIMD(const uint8_t* szPattern, const char* szMask, c
{
if (szMask[i * 16 + j] == 'x')
{
_bittestandset(reinterpret_cast<LONG*>(&nMasks[i]), j);
_bittestandset(reinterpret_cast<LONG*>(&nMasks[i]), static_cast<LONG>(j));
}
}
}

View File

@ -174,13 +174,13 @@ struct RPakHeader_t
uint8_t unk3[0x8]; //
};
struct __declspec(align(8)) RPakPatchCompressedHeader_t
struct RPakPatchCompressedHeader_t
{
uint64_t m_nSizeDisk;
uint64_t m_nSizeMemory;
};
struct __declspec(align(8)) RPakDecompState_t
struct RPakDecompState_t
{
uint64_t m_nInputBuf;
uint64_t m_nOut;
@ -238,7 +238,7 @@ struct RPakDescriptor_t
uint32_t m_Offset;
};
struct __declspec(align(2)) PakFile_t
struct PakFile_t
{
int m_nDescCount;
int m_nProcessedAssetCount;
@ -284,6 +284,10 @@ struct __declspec(align(2)) PakFile_t
RPakHeader_t m_PakHdr;
};
static_assert(sizeof(PakFile_t) == 2208);
static_assert(sizeof(RPakDecompState_t) == 136);
static_assert(sizeof(RPakPatchCompressedHeader_t) == 16);
/* ==== RTECH =========================================================================================================================================================== */
#if not defined DEDICATED
inline CMemory p_RTech_CreateDXTexture;

View File

@ -823,7 +823,7 @@ void ConVar::ChangeStringValue(const char* pszTempVal)
char* pszOldValue = (char*)stackalloc(m_Value.m_iStringLength);
memcpy(pszOldValue, m_Value.m_pszString, m_Value.m_iStringLength);
int len = strlen(pszTempVal) + 1;
size_t len = strlen(pszTempVal) + 1;
if (len > m_Value.m_iStringLength)
{

View File

@ -58,7 +58,7 @@ CCommand::CCommand(int nArgC, const char** ppArgV, cmd_source_t source)
for (int i = 0; i < nArgC; ++i)
{
m_ppArgv[i] = pBuf;
int nLen = strlen(ppArgV[i]);
int64 nLen = strlen(ppArgV[i]);
memcpy(pBuf, ppArgV[i], nLen + 1);
if (i == 0)
{

View File

@ -413,10 +413,10 @@ void CCvarUtilities::EnableDevCvars()
void CCvarUtilities::CvarList(const CCommand& args)
{
ConCommandBase* var; // Temporary Pointer to cvars
int iArgs; // Argument count
int64 iArgs; // Argument count
const char* partial = NULL; // Partial cvar to search for...
// E.eg
int ipLen = 0; // Length of the partial cvar
size_t ipLen = 0; // Length of the partial cvar
FileHandle_t f = FILESYSTEM_INVALID_HANDLE; // FilePointer for logging
bool bLogging = false;
@ -641,7 +641,7 @@ int CCvarUtilities::CvarFindFlagsCompletionCallback(const char* partial, char co
{
int flagC = ARRAYSIZE(g_ConVarFlags);
char const* pcmd = "findflags ";
int len = Q_strlen(partial);
size_t len = Q_strlen(partial);
if (len < Q_strlen(pcmd))
{
@ -655,7 +655,7 @@ int CCvarUtilities::CvarFindFlagsCompletionCallback(const char* partial, char co
}
char const* pSub = partial + Q_strlen(pcmd);
int nSubLen = Q_strlen(pSub);
size_t nSubLen = Q_strlen(pSub);
int values = 0;
for (int i = 0; i < flagC; ++i)

View File

@ -129,7 +129,7 @@ unsigned FASTCALL HashStringCaseless(const char* pszKey)
uint32 FASTCALL HashStringCaselessConventional(const char* pszKey)
{
uint32 hash = 0xAAAAAAAA; // Alternating 1's and 0's to maximize the effect of the later multiply and add
hash += (2 * V_strlen(pszKey)); // Add the string length * 2 to the hash to give it more variety
hash += (2 * (uint32)V_strlen(pszKey)); // Add the string length * 2 to the hash to give it more variety
for (; *pszKey; pszKey++)
{
@ -358,7 +358,7 @@ uint32 MurmurHash2(const void* key, int len, uint32 seed)
#define TOLOWERU( c ) ( ( uint32 ) ( ( ( c >= 'A' ) && ( c <= 'Z' ) )? c + 32 : c ) )
uint32 MurmurHash2LowerCase(char const* pString, uint32 nSeed)
{
int nLen = V_strlen(pString);
int nLen = (int)V_strlen(pString);
char* p = (char*)stackalloc(nLen + 1);
for (int i = 0; i < nLen; i++)
{

View File

@ -41,7 +41,7 @@ void CSplitString::Construct(const char* pString, const char** pSeparators, int
// make a duplicate of the original string. We'll use pieces of this duplicate to tokenize the string
// and create NULL-terminated tokens of the original string
//
int nOriginalStringLength = strlen(pString);
size_t nOriginalStringLength = strlen(pString);
m_szBuffer = new char[nOriginalStringLength + 1];
memcpy(m_szBuffer, pString, nOriginalStringLength + 1);
@ -64,13 +64,13 @@ void CSplitString::Construct(const char* pString, const char** pSeparators, int
if (pFirstSeparator)
{
// Split on this separator and continue on.
int separatorLen = strlen(pSeparators[iFirstSeparator]);
size_t separatorLen = strlen(pSeparators[iFirstSeparator]);
if (pFirstSeparator > pCurPos)
{
//////////////////////////////////////////////////////////////////////////
/// Cut the token out of the duplicate string
char* pTokenInDuplicate = m_szBuffer + (pCurPos - pString);
int nTokenLength = pFirstSeparator - pCurPos;
int64 nTokenLength = pFirstSeparator - pCurPos;
//Assert(nTokenLength > 0 && !memcmp(pTokenInDuplicate, pCurPos, nTokenLength));
pTokenInDuplicate[nTokenLength] = '\0';
@ -82,7 +82,7 @@ void CSplitString::Construct(const char* pString, const char** pSeparators, int
else
{
// Copy the rest of the string
if (int nTokenLength = strlen(pCurPos))
if (size_t nTokenLength = strlen(pCurPos))
{
//////////////////////////////////////////////////////////////////////////
// There's no need to cut this token, because there's no separator after it.

View File

@ -441,7 +441,7 @@ void* CUtlBuffer::DetachMemory()
//-----------------------------------------------------------------------------
// Makes sure we've got at least this much memory
//-----------------------------------------------------------------------------
void CUtlBuffer::EnsureCapacity(int num)
void CUtlBuffer::EnsureCapacity(int64 num)
{
//MEM_ALLOC_CREDIT();
// Add one extra for the null termination
@ -972,7 +972,7 @@ const void* CUtlBuffer::PeekGet(int64 nMaxSize, int64 nOffset)
//-----------------------------------------------------------------------------
// Change where I'm reading
//-----------------------------------------------------------------------------
void CUtlBuffer::SeekGet(SeekType_t type, int offset)
void CUtlBuffer::SeekGet(SeekType_t type, int64 offset)
{
switch (type)
{
@ -1212,22 +1212,22 @@ bool CUtlBuffer::GetToken(const char* pToken)
Assert(pToken);
// Look for the token
int nLen = V_strlen(pToken);
int64 nLen = V_strlen(pToken);
// First time through on streaming, check what we already have loaded
// if we have enough loaded to do the check
int nMaxSize = Size() - (TellGet() - m_nOffset);
int64 nMaxSize = Size() - (TellGet() - m_nOffset);
if (nMaxSize <= nLen)
{
nMaxSize = Size();
}
int nSizeRemaining = TellMaxPut() - TellGet();
int64 nSizeRemaining = TellMaxPut() - TellGet();
int nGet = TellGet();
int64 nGet = TellGet();
while (nSizeRemaining >= nLen)
{
bool bOverFlow = (nSizeRemaining > nMaxSize);
int nSizeToCheck = bOverFlow ? nMaxSize : nSizeRemaining;
int64 nSizeToCheck = bOverFlow ? nMaxSize : nSizeRemaining;
if (!CheckPeekGet(0, nSizeToCheck))
break;
@ -1239,7 +1239,7 @@ bool CUtlBuffer::GetToken(const char* pToken)
// we could be looking for 'foo' for example, and find 'foobar'
// if 'foo' happens to be the last 3 characters of the current window
size_t nOffset = (size_t)pFoundEnd - (size_t)pBufStart;
bool bPotentialMismatch = (bOverFlow && ((int)nOffset == Size() - nLen));
bool bPotentialMismatch = (bOverFlow && ((int64)nOffset == Size() - nLen));
if (!pFoundEnd || bPotentialMismatch)
{
nSizeRemaining -= nSizeToCheck;
@ -1256,7 +1256,7 @@ bool CUtlBuffer::GetToken(const char* pToken)
}
// Seek past the end of the found string
SeekGet(CUtlBuffer::SEEK_CURRENT, (int)(nOffset + nLen));
SeekGet(CUtlBuffer::SEEK_CURRENT, (int64)(nOffset + nLen));
return true;
}
@ -1293,9 +1293,9 @@ bool CUtlBuffer::ParseToken(const char* pStartingDelim, const char* pEndingDelim
Assert(pEndingDelim && pEndingDelim[0]);
nEndingDelimLen = V_strlen(pEndingDelim);
int nStartGet = TellGet();
int64 nStartGet = TellGet();
int64 nTokenStart = -1;
char nCurrChar;
int nTokenStart = -1;
EatWhiteSpace();
while (*pStartingDelim)
{
@ -1445,7 +1445,7 @@ int CUtlBuffer::ParseToken(characterset_t* pBreaks, char* pTokenBuf, int nMaxLen
//-----------------------------------------------------------------------------
// Serialization
//-----------------------------------------------------------------------------
void CUtlBuffer::Put(const void* pMem, int size)
void CUtlBuffer::Put(const void* pMem, int64 size)
{
if (size && CheckPut(size))
{
@ -1555,8 +1555,8 @@ void CUtlBuffer::PutDelimitedString(CUtlCharConversion* pConv, const char* pStri
}
Put(pConv->GetDelimiter(), pConv->GetDelimiterLength());
int nLen = pString ? V_strlen(pString) : 0;
for (int i = 0; i < nLen; ++i)
size_t nLen = pString ? V_strlen(pString) : 0;
for (size_t i = 0; i < nLen; ++i)
{
PutDelimitedCharInternal(pConv, pString[i]);
}
@ -1659,9 +1659,9 @@ bool CUtlBuffer::CheckPut(int64 nSize)
return true;
}
void CUtlBuffer::SeekPut(SeekType_t type, int offset)
void CUtlBuffer::SeekPut(SeekType_t type, int64 offset)
{
int nNextPut = m_Put;
int64 nNextPut = m_Put;
switch (type)
{
case SEEK_HEAD:
@ -1745,7 +1745,7 @@ bool CUtlBuffer::ConvertCRLF(CUtlBuffer& outBuf)
if (ContainsCRLF() == outBuf.ContainsCRLF())
return false;
int nInCount = TellMaxPut();
int64 nInCount = TellMaxPut();
outBuf.Purge();
outBuf.EnsureCapacity(nInCount);
@ -1753,10 +1753,10 @@ bool CUtlBuffer::ConvertCRLF(CUtlBuffer& outBuf)
bool bFromCRLF = ContainsCRLF();
// Start reading from the beginning
int nGet = TellGet();
int nPut = TellPut();
int nGetDelta = 0;
int nPutDelta = 0;
int64 nGet = TellGet();
int64 nPut = TellPut();
int64 nGetDelta = 0;
int64 nPutDelta = 0;
const char* pBase = (const char*)Base();
intptr_t nCurrGet = 0;
@ -1765,7 +1765,7 @@ bool CUtlBuffer::ConvertCRLF(CUtlBuffer& outBuf)
const char* pCurr = &pBase[nCurrGet];
if (bFromCRLF)
{
const char* pNext = V_strnistr(pCurr, "\r\n", nInCount - nCurrGet);
const char* pNext = V_strnistr(pCurr, "\r\n", (int)nInCount - (int)nCurrGet);
if (!pNext)
{
outBuf.Put(pCurr, nInCount - nCurrGet);
@ -1787,15 +1787,15 @@ bool CUtlBuffer::ConvertCRLF(CUtlBuffer& outBuf)
}
else
{
const char* pNext = V_strnchr(pCurr, '\n', nInCount - nCurrGet);
const char* pNext = V_strnchr(pCurr, '\n', (int)nInCount - (int)nCurrGet);
if (!pNext)
{
outBuf.Put(pCurr, nInCount - nCurrGet);
outBuf.Put(pCurr, (int64)nInCount - (int64)nCurrGet);
break;
}
intptr_t nBytes = (intptr_t)pNext - (intptr_t)pCurr;
outBuf.Put(pCurr, (int)nBytes);
outBuf.Put(pCurr, (int64)nBytes);
outBuf.PutChar('\r');
outBuf.PutChar('\n');
nCurrGet += nBytes + 1;

View File

@ -192,10 +192,10 @@ public:
void SetBufferType(bool bIsText, bool bContainsCRLF);
// Makes sure we've got at least this much memory
void EnsureCapacity(int num);
void EnsureCapacity(int64 num);
// Access for direct read into buffer
void* AccessForDirectRead(int nBytes);
void* AccessForDirectRead(int64 nBytes);
// Attaches the buffer to external memory....
void SetExternalBuffer(void* pMemory, int nSize, int nInitialPut, int nFlags = 0);
@ -206,7 +206,7 @@ public:
// copies data from another buffer
void CopyBuffer(const CUtlBuffer& buffer);
void CopyBuffer(const void* pubData, int cubData);
void CopyBuffer(const void* pubData, int64 cubData);
void Swap(CUtlBuffer& buf);
void Swap(CUtlMemory<uint8>& mem);
@ -326,7 +326,7 @@ public:
void PutDouble(double d);
void PutPtr(void*); // Writes the pointer, not the pointed to
void PutString(const char* pString);
void Put(const void* pMem, int size);
void Put(const void* pMem, int64 size);
// Used for putting objects that have a byteswap datadesc defined
template <typename T> void PutObjects(T* src, int count = 1);
@ -357,8 +357,8 @@ public:
int64 GetBytesRemaining() const;
// Change where I'm writing (put)/reading (get)
void SeekPut(SeekType_t type, int offset);
void SeekGet(SeekType_t type, int offset);
void SeekPut(SeekType_t type, int64 offset);
void SeekGet(SeekType_t type, int64 offset);
// Buffer base
const void* Base() const;
@ -366,7 +366,7 @@ public:
// memory allocation size, does *not* reflect size written or read,
// use TellPut or TellGet for that
int Size() const;
int64 Size() const;
// Am I a text buffer?
bool IsText() const;
@ -976,7 +976,7 @@ inline void* CUtlBuffer::GetPtr()
void* p;
// LEGACY WARNING: in text mode, PutPtr writes 32 bit pointers in hex, while GetPtr reads 32 or 64 bit pointers in decimal
#if !defined(X64BITS) && !defined(PLATFORM_64BITS)
p = (void*)GetUnsignedInt();
p = (void*)GetUnsignedInt64();
#else
p = (void*)GetInt64();
#endif
@ -1352,7 +1352,7 @@ inline void* CUtlBuffer::Base()
return m_Memory.Base();
}
inline int CUtlBuffer::Size() const
inline int64 CUtlBuffer::Size() const
{
return m_Memory.NumAllocated();
}
@ -1384,7 +1384,7 @@ inline void CUtlBuffer::Purge()
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
inline void* CUtlBuffer::AccessForDirectRead(int nBytes)
inline void* CUtlBuffer::AccessForDirectRead(int64 nBytes)
{
Assert(m_Get == 0 && m_Put == 0 && m_nMaxPut == 0);
EnsureCapacity(nBytes);
@ -1438,7 +1438,7 @@ inline void CUtlBuffer::CopyBuffer(const CUtlBuffer& buffer)
CopyBuffer(buffer.Base(), buffer.TellPut());
}
inline void CUtlBuffer::CopyBuffer(const void* pubData, int cubData)
inline void CUtlBuffer::CopyBuffer(const void* pubData, int64 cubData)
{
Clear();
if (cubData)

View File

@ -39,16 +39,16 @@
// The CUtlMemory class:
// A growable memory class which doubles in size by default.
//-----------------------------------------------------------------------------
template< class T, class I = ssize_t >
template< class T, class I = int64 >
class CUtlMemory
{
template< class A, class B> friend class CUtlVector;
template< class A, size_t B> friend class CUtlVectorFixedGrowableCompat;
public:
// constructor, destructor
CUtlMemory(ssize_t nGrowSize = 0, ssize_t nInitSize = 0);
CUtlMemory(T* pMemory, ssize_t numElements);
CUtlMemory(const T* pMemory, ssize_t numElements);
CUtlMemory(int64 nGrowSize = 0, int64 nInitSize = 0);
CUtlMemory(T* pMemory, int64 numElements);
CUtlMemory(const T* pMemory, int64 numElements);
~CUtlMemory();
CUtlMemory(const CUtlMemory&) = delete;
@ -58,7 +58,7 @@ public:
CUtlMemory& operator=(CUtlMemory&& moveFrom);
// Set the size by which the memory grows
void Init(ssize_t nGrowSize = 0, ssize_t nInitSize = 0);
void Init(int64 nGrowSize = 0, int64 nInitSize = 0);
class Iterator_t
{
@ -94,9 +94,9 @@ public:
const T* Base() const;
// Attaches the buffer to external memory....
void SetExternalBuffer(T* pMemory, ssize_t numElements);
void SetExternalBuffer(const T* pMemory, ssize_t numElements);
void AssumeMemory(T* pMemory, ssize_t nSize);
void SetExternalBuffer(T* pMemory, int64 numElements);
void SetExternalBuffer(const T* pMemory, int64 numElements);
void AssumeMemory(T* pMemory, int64 nSize);
T* Detach();
void* DetachMemory();
@ -105,23 +105,23 @@ public:
// Switches the buffer from an external memory buffer to a reallocatable buffer
// Will copy the current contents of the external buffer to the reallocatable buffer
void ConvertToGrowableMemory(ssize_t nGrowSize);
void ConvertToGrowableMemory(int64 nGrowSize);
// Size
ssize_t NumAllocated() const;
ssize_t Count() const;
int64 NumAllocated() const;
int64 Count() const;
// Grows the memory, so that at least allocated + num elements are allocated
void Grow(ssize_t num = 1);
void Grow(int64 num = 1);
// Makes sure we've got at least this much memory
void EnsureCapacity(ssize_t num);
void EnsureCapacity(int64 num);
// Memory deallocation
void Purge();
// Purge all but the given number of elements
void Purge(ssize_t numElements);
void Purge(int64 numElements);
// is the memory externally allocated?
bool IsExternallyAllocated() const;
@ -130,7 +130,7 @@ public:
bool IsReadOnly() const;
// Set the size by which the memory grows
void SetGrowSize(ssize_t size);
void SetGrowSize(int64 size);
protected:
void ValidateGrowSize()
@ -139,7 +139,7 @@ protected:
if (m_nGrowSize && m_nGrowSize != EXTERNAL_BUFFER_MARKER)
{
// Max grow size at 128 bytes on XBOX
const ssize_t MAX_GROW = 128;
const int64 MAX_GROW = 128;
if (m_nGrowSize * sizeof(T) > MAX_GROW)
{
m_nGrowSize = max(1, MAX_GROW / sizeof(T));
@ -155,8 +155,8 @@ protected:
};
T* m_pMemory;
ssize_t m_nAllocationCount;
ssize_t m_nGrowSize;
int64 m_nAllocationCount;
int64 m_nGrowSize;
};
@ -164,19 +164,19 @@ protected:
// The CUtlMemory class:
// A growable memory class which doubles in size by default.
//-----------------------------------------------------------------------------
template< class T, size_t SIZE, class I = ssize_t >
template< class T, size_t SIZE, class I = int64 >
class CUtlMemoryFixedGrowable : public CUtlMemory< T, I >
{
typedef CUtlMemory< T, I > BaseClass;
public:
CUtlMemoryFixedGrowable(ssize_t nGrowSize = 0, ssize_t nInitSize = SIZE) : BaseClass(m_pFixedMemory, SIZE)
CUtlMemoryFixedGrowable(int64 nGrowSize = 0, int64 nInitSize = SIZE) : BaseClass(m_pFixedMemory, SIZE)
{
Assert(nInitSize == 0 || nInitSize == SIZE);
m_nMallocGrowSize = nGrowSize;
}
void Grow(ssize_t nCount = 1)
void Grow(int64 nCount = 1)
{
if (this->IsExternallyAllocated())
{
@ -185,7 +185,7 @@ public:
BaseClass::Grow(nCount);
}
void EnsureCapacity(ssize_t num)
void EnsureCapacity(int64 num)
{
if (CUtlMemory<T>::m_nAllocationCount >= num)
return;
@ -200,7 +200,7 @@ public:
}
private:
ssize_t m_nMallocGrowSize;
int64 m_nMallocGrowSize;
T m_pFixedMemory[SIZE];
};
@ -208,68 +208,68 @@ private:
// The CUtlMemoryFixed class:
// A fixed memory class
//-----------------------------------------------------------------------------
template< typename T, size_t SIZE, ssize_t nAlignment = 0 >
template< typename T, size_t SIZE, int64 nAlignment = 0 >
class CUtlMemoryFixed
{
public:
// constructor, destructor
CUtlMemoryFixed(ssize_t nGrowSize = 0, ssize_t nInitSize = 0) { Assert(nInitSize == 0 || nInitSize == SIZE); }
CUtlMemoryFixed(T* pMemory, ssize_t numElements) { Assert(0); }
CUtlMemoryFixed(int64 nGrowSize = 0, int64 nInitSize = 0) { Assert(nInitSize == 0 || nInitSize == SIZE); }
CUtlMemoryFixed(T* pMemory, int64 numElements) { Assert(0); }
// Can we use this index?
bool IsIdxValid(ssize_t i) const { return (i >= 0) && (i < SIZE); }
bool IsIdxValid(int64 i) const { return (i >= 0) && (i < SIZE); }
// Specify the invalid ('null') index that we'll only return on failure
static const ssize_t INVALID_INDEX = -1; // For use with COMPILE_TIME_ASSERT
static ssize_t InvalidIndex() { return INVALID_INDEX; }
static const int64 INVALID_INDEX = -1; // For use with COMPILE_TIME_ASSERT
static int64 InvalidIndex() { return INVALID_INDEX; }
// Gets the base address
T* Base() { if (nAlignment == 0) return (T*)(&m_Memory[0]); else return (T*)AlignValue(&m_Memory[0], nAlignment); }
const T* Base() const { if (nAlignment == 0) return (T*)(&m_Memory[0]); else return (T*)AlignValue(&m_Memory[0], nAlignment); }
// element access
T& operator[](ssize_t i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& operator[](ssize_t i) const { Assert(IsIdxValid(i)); return Base()[i]; }
T& Element(ssize_t i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& Element(ssize_t i) const { Assert(IsIdxValid(i)); return Base()[i]; }
T& operator[](int64 i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& operator[](int64 i) const { Assert(IsIdxValid(i)); return Base()[i]; }
T& Element(int64 i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& Element(int64 i) const { Assert(IsIdxValid(i)); return Base()[i]; }
// Attaches the buffer to external memory....
void SetExternalBuffer(T* pMemory, ssize_t numElements) { Assert(0); }
void SetExternalBuffer(T* pMemory, int64 numElements) { Assert(0); }
// Size
ssize_t NumAllocated() const { return SIZE; }
ssize_t Count() const { return SIZE; }
int64 NumAllocated() const { return SIZE; }
int64 Count() const { return SIZE; }
// Grows the memory, so that at least allocated + num elements are allocated
void Grow(ssize_t num = 1) { Assert(0); }
void Grow(int64 num = 1) { Assert(0); }
// Makes sure we've got at least this much memory
void EnsureCapacity(ssize_t num) { Assert(num <= SIZE); }
void EnsureCapacity(int64 num) { Assert(num <= SIZE); }
// Memory deallocation
void Purge() {}
// Purge all but the given number of elements (NOT IMPLEMENTED IN CUtlMemoryFixed)
void Purge(ssize_t numElements) { Assert(0); }
void Purge(int64 numElements) { Assert(0); }
// is the memory externally allocated?
bool IsExternallyAllocated() const { return false; }
// Set the size by which the memory grows
void SetGrowSize(ssize_t size) {}
void SetGrowSize(int64 size) {}
class Iterator_t
{
public:
Iterator_t(ssize_t i) : index(i) {}
ssize_t index;
Iterator_t(int64 i) : index(i) {}
int64 index;
bool operator==(const Iterator_t it) const { return index == it.index; }
bool operator!=(const Iterator_t it) const { return index != it.index; }
};
Iterator_t First() const { return Iterator_t(IsIdxValid(0) ? 0 : InvalidIndex()); }
Iterator_t Next(const Iterator_t& it) const { return Iterator_t(IsIdxValid(it.index + 1) ? it.index + 1 : InvalidIndex()); }
ssize_t GetIndex(const Iterator_t& it) const { return it.index; }
bool IsIdxAfter(ssize_t i, const Iterator_t& it) const { return i > it.index; }
int64 GetIndex(const Iterator_t& it) const { return it.index; }
bool IsIdxAfter(int64 i, const Iterator_t& it) const { return i > it.index; }
bool IsValidIterator(const Iterator_t& it) const { return IsIdxValid(it.index); }
Iterator_t InvalidIterator() const { return Iterator_t(InvalidIndex()); }
@ -291,32 +291,32 @@ class CUtlMemoryConservative
public:
// constructor, destructor
CUtlMemoryConservative(ssize_t nGrowSize = 0, ssize_t nInitSize = 0) : m_pMemory(NULL)
CUtlMemoryConservative(int64 nGrowSize = 0, int64 nInitSize = 0) : m_pMemory(NULL)
{
#ifdef REMEMBER_ALLOC_SIZE_FOR_VALGRIND
m_nCurAllocSize = 0;
#endif
}
CUtlMemoryConservative(T* pMemory, ssize_t numElements) { Assert(0); }
CUtlMemoryConservative(T* pMemory, int64 numElements) { Assert(0); }
~CUtlMemoryConservative() { if (m_pMemory) free(m_pMemory); }
// Can we use this index?
bool IsIdxValid(ssize_t i) const { return (IsDebug()) ? (i >= 0 && i < NumAllocated()) : (i >= 0); }
static ssize_t InvalidIndex() { return -1; }
bool IsIdxValid(int64 i) const { return (IsDebug()) ? (i >= 0 && i < NumAllocated()) : (i >= 0); }
static int64 InvalidIndex() { return -1; }
// Gets the base address
T* Base() { return m_pMemory; }
const T* Base() const { return m_pMemory; }
// element access
T& operator[](ssize_t i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& operator[](ssize_t i) const { Assert(IsIdxValid(i)); return Base()[i]; }
T& Element(ssize_t i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& Element(ssize_t i) const { Assert(IsIdxValid(i)); return Base()[i]; }
T& operator[](int64 i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& operator[](int64 i) const { Assert(IsIdxValid(i)); return Base()[i]; }
T& Element(int64 i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& Element(int64 i) const { Assert(IsIdxValid(i)); return Base()[i]; }
// Attaches the buffer to external memory....
void SetExternalBuffer(T* pMemory, ssize_t numElements) { Assert(0); }
void SetExternalBuffer(T* pMemory, int64 numElements) { Assert(0); }
// Size
FORCEINLINE void RememberAllocSize(size_t sz)
@ -335,11 +335,11 @@ public:
#endif
}
ssize_t NumAllocated() const
int64 NumAllocated() const
{
return AllocSize() / sizeof(T);
}
ssize_t Count() const
int64 Count() const
{
return NumAllocated();
}
@ -350,14 +350,14 @@ public:
RememberAllocSize(sz);
}
// Grows the memory, so that at least allocated + num elements are allocated
void Grow(ssize_t num = 1)
void Grow(int64 num = 1)
{
ssize_t nCurN = NumAllocated();
int64 nCurN = NumAllocated();
ReAlloc((nCurN + num) * sizeof(T));
}
// Makes sure we've got at least this much memory
void EnsureCapacity(ssize_t num)
void EnsureCapacity(int64 num)
{
size_t nSize = sizeof(T) * MAX(num, Count());
ReAlloc(nSize);
@ -372,27 +372,27 @@ public:
}
// Purge all but the given number of elements
void Purge(ssize_t numElements) { ReAlloc(numElements * sizeof(T)); }
void Purge(int64 numElements) { ReAlloc(numElements * sizeof(T)); }
// is the memory externally allocated?
bool IsExternallyAllocated() const { return false; }
// Set the size by which the memory grows
void SetGrowSize(ssize_t size) {}
void SetGrowSize(int64 size) {}
class Iterator_t
{
public:
Iterator_t(ssize_t i, ssize_t _limit) : index(i), limit(_limit) {}
ssize_t index;
ssize_t limit;
Iterator_t(int64 i, int64 _limit) : index(i), limit(_limit) {}
int64 index;
int64 limit;
bool operator==(const Iterator_t it) const { return index == it.index; }
bool operator!=(const Iterator_t it) const { return index != it.index; }
};
Iterator_t First() const { ssize_t limit = NumAllocated(); return Iterator_t(limit ? 0 : InvalidIndex(), limit); }
Iterator_t First() const { int64 limit = NumAllocated(); return Iterator_t(limit ? 0 : InvalidIndex(), limit); }
Iterator_t Next(const Iterator_t& it) const { return Iterator_t((it.index + 1 < it.limit) ? it.index + 1 : InvalidIndex(), it.limit); }
ssize_t GetIndex(const Iterator_t& it) const { return it.index; }
bool IsIdxAfter(ssize_t i, const Iterator_t& it) const { return i > it.index; }
int64 GetIndex(const Iterator_t& it) const { return it.index; }
bool IsIdxAfter(int64 i, const Iterator_t& it) const { return i > it.index; }
bool IsValidIterator(const Iterator_t& it) const { return IsIdxValid(it.index) && (it.index < it.limit); }
Iterator_t InvalidIterator() const { return Iterator_t(InvalidIndex(), 0); }
@ -410,7 +410,7 @@ private:
//-----------------------------------------------------------------------------
template< class T, class I >
CUtlMemory<T, I>::CUtlMemory(ssize_t nGrowSize, ssize_t nInitAllocationCount) : m_pMemory(0),
CUtlMemory<T, I>::CUtlMemory(int64 nGrowSize, int64 nInitAllocationCount) : m_pMemory(0),
m_nAllocationCount(nInitAllocationCount), m_nGrowSize(nGrowSize)
{
ValidateGrowSize();
@ -424,7 +424,7 @@ m_nAllocationCount(nInitAllocationCount), m_nGrowSize(nGrowSize)
}
template< class T, class I >
CUtlMemory<T, I>::CUtlMemory(T* pMemory, ssize_t numElements) : m_pMemory(pMemory),
CUtlMemory<T, I>::CUtlMemory(T* pMemory, int64 numElements) : m_pMemory(pMemory),
m_nAllocationCount(numElements)
{
// Special marker indicating externally supplied modifiable memory
@ -432,7 +432,7 @@ m_nAllocationCount(numElements)
}
template< class T, class I >
CUtlMemory<T, I>::CUtlMemory(const T* pMemory, ssize_t numElements) : m_pMemory((T*)pMemory),
CUtlMemory<T, I>::CUtlMemory(const T* pMemory, int64 numElements) : m_pMemory((T*)pMemory),
m_nAllocationCount(numElements)
{
// Special marker indicating externally supplied modifiable memory
@ -466,8 +466,8 @@ CUtlMemory<T, I>& CUtlMemory<T, I>::operator=(CUtlMemory&& moveFrom)
{
// Copy member variables to locals before purge to handle self-assignment
T* pMemory = moveFrom.m_pMemory;
ssize_t nAllocationCount = moveFrom.m_nAllocationCount;
ssize_t nGrowSize = moveFrom.m_nGrowSize;
int64 nAllocationCount = moveFrom.m_nAllocationCount;
int64 nGrowSize = moveFrom.m_nGrowSize;
moveFrom.m_pMemory = nullptr;
moveFrom.m_nAllocationCount = 0;
@ -484,7 +484,7 @@ CUtlMemory<T, I>& CUtlMemory<T, I>::operator=(CUtlMemory&& moveFrom)
}
template< class T, class I >
void CUtlMemory<T, I>::Init(ssize_t nGrowSize /*= 0*/, ssize_t nInitSize /*= 0*/)
void CUtlMemory<T, I>::Init(int64 nGrowSize /*= 0*/, int64 nInitSize /*= 0*/)
{
Purge();
@ -516,7 +516,7 @@ void CUtlMemory<T, I>::Swap(CUtlMemory<T, I>& mem)
// Switches the buffer from an external memory buffer to a reallocatable buffer
//-----------------------------------------------------------------------------
template< class T, class I >
void CUtlMemory<T, I>::ConvertToGrowableMemory(ssize_t nGrowSize)
void CUtlMemory<T, I>::ConvertToGrowableMemory(int64 nGrowSize)
{
if (!IsExternallyAllocated())
return;
@ -527,7 +527,7 @@ void CUtlMemory<T, I>::ConvertToGrowableMemory(ssize_t nGrowSize)
UTLMEMORY_TRACK_ALLOC();
MEM_ALLOC_CREDIT_CLASS();
ssize_t nNumBytes = m_nAllocationCount * sizeof(T);
int64 nNumBytes = m_nAllocationCount * sizeof(T);
T* pMemory = MemAllocSingleton()->Alloc<T>(nNumBytes);
memcpy(pMemory, m_pMemory, nNumBytes);
m_pMemory = pMemory;
@ -543,7 +543,7 @@ void CUtlMemory<T, I>::ConvertToGrowableMemory(ssize_t nGrowSize)
// Attaches the buffer to external memory....
//-----------------------------------------------------------------------------
template< class T, class I >
void CUtlMemory<T, I>::SetExternalBuffer(T* pMemory, ssize_t numElements)
void CUtlMemory<T, I>::SetExternalBuffer(T* pMemory, int64 numElements)
{
// Blow away any existing allocated memory
Purge();
@ -556,7 +556,7 @@ void CUtlMemory<T, I>::SetExternalBuffer(T* pMemory, ssize_t numElements)
}
template< class T, class I >
void CUtlMemory<T, I>::SetExternalBuffer(const T* pMemory, ssize_t numElements)
void CUtlMemory<T, I>::SetExternalBuffer(const T* pMemory, int64 numElements)
{
// Blow away any existing allocated memory
Purge();
@ -569,7 +569,7 @@ void CUtlMemory<T, I>::SetExternalBuffer(const T* pMemory, ssize_t numElements)
}
template< class T, class I >
void CUtlMemory<T, I>::AssumeMemory(T* pMemory, ssize_t numElements)
void CUtlMemory<T, I>::AssumeMemory(T* pMemory, int64 numElements)
{
// Blow away any existing allocated memory
Purge();
@ -653,7 +653,7 @@ bool CUtlMemory<T, I>::IsReadOnly() const
template< class T, class I >
void CUtlMemory<T, I>::SetGrowSize(ssize_t nSize)
void CUtlMemory<T, I>::SetGrowSize(int64 nSize)
{
Assert(!IsExternallyAllocated());
Assert(nSize >= 0);
@ -683,13 +683,13 @@ inline const T* CUtlMemory<T, I>::Base() const
// Size
//-----------------------------------------------------------------------------
template< class T, class I >
inline ssize_t CUtlMemory<T, I>::NumAllocated() const
inline int64 CUtlMemory<T, I>::NumAllocated() const
{
return m_nAllocationCount;
}
template< class T, class I >
inline ssize_t CUtlMemory<T, I>::Count() const
inline int64 CUtlMemory<T, I>::Count() const
{
return m_nAllocationCount;
}
@ -710,7 +710,7 @@ inline bool CUtlMemory<T, I>::IsIdxValid(I i) const
//-----------------------------------------------------------------------------
// Grows the memory
//-----------------------------------------------------------------------------
inline ssize_t UtlMemory_CalcNewAllocationCount(ssize_t nAllocationCount, ssize_t nGrowSize, ssize_t nNewSize, ssize_t nBytesItem)
inline int64 UtlMemory_CalcNewAllocationCount(int64 nAllocationCount, int64 nGrowSize, int64 nNewSize, int64 nBytesItem)
{
if (nGrowSize)
{
@ -734,7 +734,7 @@ inline ssize_t UtlMemory_CalcNewAllocationCount(ssize_t nAllocationCount, ssize_
#ifndef _X360
nAllocationCount *= 2;
#else
ssize_t nNewAllocationCount = (nAllocationCount * 9) / 8; // 12.5 %
int64 nNewAllocationCount = (nAllocationCount * 9) / 8; // 12.5 %
if (nNewAllocationCount > nAllocationCount)
nAllocationCount = nNewAllocationCount;
else
@ -747,7 +747,7 @@ inline ssize_t UtlMemory_CalcNewAllocationCount(ssize_t nAllocationCount, ssize_
}
template< class T, class I >
void CUtlMemory<T, I>::Grow(ssize_t num)
void CUtlMemory<T, I>::Grow(int64 num)
{
Assert(num > 0);
@ -760,28 +760,28 @@ void CUtlMemory<T, I>::Grow(ssize_t num)
// Make sure we have at least numallocated + num allocations.
// Use the grow rules specified for this memory (in m_nGrowSize)
ssize_t nAllocationRequested = m_nAllocationCount + num;
int64 nAllocationRequested = m_nAllocationCount + num;
UTLMEMORY_TRACK_FREE();
ssize_t nNewAllocationCount = UtlMemory_CalcNewAllocationCount(m_nAllocationCount, m_nGrowSize, nAllocationRequested, sizeof(T));
int64 nNewAllocationCount = UtlMemory_CalcNewAllocationCount(m_nAllocationCount, m_nGrowSize, nAllocationRequested, sizeof(T));
// if m_nAllocationRequested wraps index type I, recalculate
if ((ssize_t)(I)nNewAllocationCount < nAllocationRequested)
if ((int64)(I)nNewAllocationCount < nAllocationRequested)
{
if ((ssize_t)(I)nNewAllocationCount == 0 && (ssize_t)(I)(nNewAllocationCount - 1) >= nAllocationRequested)
if ((int64)(I)nNewAllocationCount == 0 && (int64)(I)(nNewAllocationCount - 1) >= nAllocationRequested)
{
--nNewAllocationCount; // deal w/ the common case of m_nAllocationCount == MAX_USHORT + 1
}
else
{
if ((ssize_t)(I)nAllocationRequested != nAllocationRequested)
if ((int64)(I)nAllocationRequested != nAllocationRequested)
{
// we've been asked to grow memory to a size s.t. the index type can't address the requested amount of memory
Assert(0);
return;
}
while ((ssize_t)(I)nNewAllocationCount < nAllocationRequested)
while ((int64)(I)nNewAllocationCount < nAllocationRequested)
{
nNewAllocationCount = (nNewAllocationCount + nAllocationRequested) / 2;
}
@ -811,7 +811,7 @@ void CUtlMemory<T, I>::Grow(ssize_t num)
// Makes sure we've got at least this much memory
//-----------------------------------------------------------------------------
template< class T, class I >
inline void CUtlMemory<T, I>::EnsureCapacity(ssize_t num)
inline void CUtlMemory<T, I>::EnsureCapacity(int64 num)
{
if (m_nAllocationCount >= num)
return;
@ -861,7 +861,7 @@ void CUtlMemory<T, I>::Purge()
}
template< class T, class I >
void CUtlMemory<T, I>::Purge(ssize_t numElements)
void CUtlMemory<T, I>::Purge(int64 numElements)
{
Assert(numElements >= 0);
@ -914,31 +914,31 @@ void CUtlMemory<T, I>::Purge(ssize_t numElements)
// The CUtlMemory class:
// A growable memory class which doubles in size by default.
//-----------------------------------------------------------------------------
template< class T, ssize_t nAlignment >
template< class T, int64 nAlignment >
class CUtlMemoryAligned : public CUtlMemory<T>
{
public:
// constructor, destructor
CUtlMemoryAligned(ssize_t nGrowSize = 0, ssize_t nInitSize = 0);
CUtlMemoryAligned(T* pMemory, ssize_t numElements);
CUtlMemoryAligned(const T* pMemory, ssize_t numElements);
CUtlMemoryAligned(int64 nGrowSize = 0, int64 nInitSize = 0);
CUtlMemoryAligned(T* pMemory, int64 numElements);
CUtlMemoryAligned(const T* pMemory, int64 numElements);
~CUtlMemoryAligned();
// Attaches the buffer to external memory....
void SetExternalBuffer(T* pMemory, ssize_t numElements);
void SetExternalBuffer(const T* pMemory, ssize_t numElements);
void SetExternalBuffer(T* pMemory, int64 numElements);
void SetExternalBuffer(const T* pMemory, int64 numElements);
// Grows the memory, so that at least allocated + num elements are allocated
void Grow(ssize_t num = 1);
void Grow(int64 num = 1);
// Makes sure we've got at least this much memory
void EnsureCapacity(ssize_t num);
void EnsureCapacity(int64 num);
// Memory deallocation
void Purge();
// Purge all but the given number of elements (NOT IMPLEMENTED IN CUtlMemoryAligned)
void Purge(ssize_t numElements) { Assert(0); }
void Purge(int64 numElements) { Assert(0); }
private:
void* Align(const void* pAddr);
@ -948,7 +948,7 @@ private:
//-----------------------------------------------------------------------------
// Aligns a pointer
//-----------------------------------------------------------------------------
template< class T, ssize_t nAlignment >
template< class T, int64 nAlignment >
void* CUtlMemoryAligned<T, nAlignment>::Align(const void* pAddr)
{
size_t nAlignmentMask = nAlignment - 1;
@ -959,8 +959,8 @@ void* CUtlMemoryAligned<T, nAlignment>::Align(const void* pAddr)
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
template< class T, ssize_t nAlignment >
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(ssize_t nGrowSize, ssize_t nInitAllocationCount)
template< class T, int64 nAlignment >
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(int64 nGrowSize, int64 nInitAllocationCount)
{
CUtlMemory<T>::m_pMemory = 0;
CUtlMemory<T>::m_nAllocationCount = nInitAllocationCount;
@ -978,27 +978,27 @@ CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(ssize_t nGrowSize, ssize_t n
}
}
template< class T, ssize_t nAlignment >
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(T* pMemory, ssize_t numElements)
template< class T, int64 nAlignment >
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(T* pMemory, int64 numElements)
{
// Special marker indicating externally supplied memory
CUtlMemory<T>::m_nGrowSize = CUtlMemory<T>::EXTERNAL_BUFFER_MARKER;
CUtlMemory<T>::m_pMemory = (T*)Align(pMemory);
CUtlMemory<T>::m_nAllocationCount = ((ssize_t)(pMemory + numElements) - (ssize_t)CUtlMemory<T>::m_pMemory) / sizeof(T);
CUtlMemory<T>::m_nAllocationCount = ((int64)(pMemory + numElements) - (int64)CUtlMemory<T>::m_pMemory) / sizeof(T);
}
template< class T, ssize_t nAlignment >
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(const T* pMemory, ssize_t numElements)
template< class T, int64 nAlignment >
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(const T* pMemory, int64 numElements)
{
// Special marker indicating externally supplied memory
CUtlMemory<T>::m_nGrowSize = CUtlMemory<T>::EXTERNAL_CONST_BUFFER_MARKER;
CUtlMemory<T>::m_pMemory = (T*)Align(pMemory);
CUtlMemory<T>::m_nAllocationCount = ((ssize_t)(pMemory + numElements) - (ssize_t)CUtlMemory<T>::m_pMemory) / sizeof(T);
CUtlMemory<T>::m_nAllocationCount = ((int64)(pMemory + numElements) - (int64)CUtlMemory<T>::m_pMemory) / sizeof(T);
}
template< class T, ssize_t nAlignment >
template< class T, int64 nAlignment >
CUtlMemoryAligned<T, nAlignment>::~CUtlMemoryAligned()
{
Purge();
@ -1008,27 +1008,27 @@ CUtlMemoryAligned<T, nAlignment>::~CUtlMemoryAligned()
//-----------------------------------------------------------------------------
// Attaches the buffer to external memory....
//-----------------------------------------------------------------------------
template< class T, ssize_t nAlignment >
void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(T* pMemory, ssize_t numElements)
template< class T, int64 nAlignment >
void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(T* pMemory, int64 numElements)
{
// Blow away any existing allocated memory
Purge();
CUtlMemory<T>::m_pMemory = (T*)Align(pMemory);
CUtlMemory<T>::m_nAllocationCount = ((ssize_t)(pMemory + numElements) - (ssize_t)CUtlMemory<T>::m_pMemory) / sizeof(T);
CUtlMemory<T>::m_nAllocationCount = ((int64)(pMemory + numElements) - (int64)CUtlMemory<T>::m_pMemory) / sizeof(T);
// Indicate that we don't own the memory
CUtlMemory<T>::m_nGrowSize = CUtlMemory<T>::EXTERNAL_BUFFER_MARKER;
}
template< class T, ssize_t nAlignment >
void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(const T* pMemory, ssize_t numElements)
template< class T, int64 nAlignment >
void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(const T* pMemory, int64 numElements)
{
// Blow away any existing allocated memory
Purge();
CUtlMemory<T>::m_pMemory = (T*)Align(pMemory);
CUtlMemory<T>::m_nAllocationCount = ((ssize_t)(pMemory + numElements) - (ssize_t)CUtlMemory<T>::m_pMemory) / sizeof(T);
CUtlMemory<T>::m_nAllocationCount = ((int64)(pMemory + numElements) - (int64)CUtlMemory<T>::m_pMemory) / sizeof(T);
// Indicate that we don't own the memory
CUtlMemory<T>::m_nGrowSize = CUtlMemory<T>::EXTERNAL_CONST_BUFFER_MARKER;
@ -1038,8 +1038,8 @@ void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(const T* pMemory, ssize
//-----------------------------------------------------------------------------
// Grows the memory
//-----------------------------------------------------------------------------
template< class T, ssize_t nAlignment >
void CUtlMemoryAligned<T, nAlignment>::Grow(ssize_t num)
template< class T, int64 nAlignment >
void CUtlMemoryAligned<T, nAlignment>::Grow(int64 num)
{
Assert(num > 0);
@ -1054,7 +1054,7 @@ void CUtlMemoryAligned<T, nAlignment>::Grow(ssize_t num)
// Make sure we have at least numallocated + num allocations.
// Use the grow rules specified for this memory (in m_nGrowSize)
ssize_t nAllocationRequested = CUtlMemory<T>::m_nAllocationCount + num;
int64 nAllocationRequested = CUtlMemory<T>::m_nAllocationCount + num;
CUtlMemory<T>::m_nAllocationCount = UtlMemory_CalcNewAllocationCount(CUtlMemory<T>::m_nAllocationCount, CUtlMemory<T>::m_nGrowSize, nAllocationRequested, sizeof(T));
@ -1078,8 +1078,8 @@ void CUtlMemoryAligned<T, nAlignment>::Grow(ssize_t num)
//-----------------------------------------------------------------------------
// Makes sure we've got at least this much memory
//-----------------------------------------------------------------------------
template< class T, ssize_t nAlignment >
inline void CUtlMemoryAligned<T, nAlignment>::EnsureCapacity(ssize_t num)
template< class T, int64 nAlignment >
inline void CUtlMemoryAligned<T, nAlignment>::EnsureCapacity(int64 num)
{
if (CUtlMemory<T>::m_nAllocationCount >= num)
return;
@ -1113,7 +1113,7 @@ inline void CUtlMemoryAligned<T, nAlignment>::EnsureCapacity(ssize_t num)
//-----------------------------------------------------------------------------
// Memory deallocation
//-----------------------------------------------------------------------------
template< class T, ssize_t nAlignment >
template< class T, int64 nAlignment >
void CUtlMemoryAligned<T, nAlignment>::Purge()
{
if (!this->IsExternallyAllocated())

View File

@ -162,7 +162,7 @@ void DebugDrawSphere(const Vector3D& vOrigin, float flRadius, Color color, int n
void DebugDrawHemiSphere(const Vector3D& vOrigin, const QAngle& vAngles, const Vector3D& vRadius, Color color, int nSegments, bool bZBuffer)
{
bool bFirstLoop = true;
float flDegrees = 360.0 / float(nSegments * 2);
float flDegrees = 360.0f / float(nSegments * 2);
Vector3D vStart[4], vEnd[4], vForward[4];
QAngle vComposed[4];

View File

@ -46,7 +46,7 @@ void CSocketCreator::ProcessAccept(void)
{
sockaddr_storage inClient{};
int nLengthAddr = sizeof(inClient);
int newSocket = ::accept(m_hListenSocket, reinterpret_cast<sockaddr*>(&inClient), &nLengthAddr);
SocketHandle_t newSocket = ::accept(m_hListenSocket, reinterpret_cast<sockaddr*>(&inClient), &nLengthAddr);
if (newSocket == -1)
{
if (!IsSocketBlocking())
@ -346,7 +346,7 @@ bool CSocketCreator::IsSocketBlocking(void) const
//-----------------------------------------------------------------------------
int CSocketCreator::GetAcceptedSocketCount(void) const
{
return m_hAcceptedSockets.size();
return static_cast<int>(m_hAcceptedSockets.size());
}
//-----------------------------------------------------------------------------