diff --git a/r5dev/public/tier1/utlblockmemory.h b/r5dev/public/tier1/utlblockmemory.h index 8043481e..8c25b80f 100644 --- a/r5dev/public/tier1/utlblockmemory.h +++ b/r5dev/public/tier1/utlblockmemory.h @@ -251,7 +251,7 @@ void CUtlBlockMemory::ChangeSize(int nBlocks) for (int i = m_nBlocks; i < nBlocksOld; ++i) { UTLBLOCKMEMORY_TRACK_FREE(); - MemAllocSingleton()->Free(m_pMemory[i]); + free((void*)m_pMemory[i]); } if (m_pMemory) @@ -305,12 +305,12 @@ void CUtlBlockMemory::Purge() for (int i = 0; i < m_nBlocks; ++i) { UTLBLOCKMEMORY_TRACK_FREE(); - MemAllocSingleton()->Free(m_pMemory[i]); + free((void*)m_pMemory[i]); } m_nBlocks = 0; UTLBLOCKMEMORY_TRACK_FREE(); - MemAllocSingleton()->Free(m_pMemory); + free((void*)m_pMemory); m_pMemory = 0; } diff --git a/r5dev/public/tier1/utlfixedmemory.h b/r5dev/public/tier1/utlfixedmemory.h index 11497a92..416d5db4 100644 --- a/r5dev/public/tier1/utlfixedmemory.h +++ b/r5dev/public/tier1/utlfixedmemory.h @@ -345,7 +345,7 @@ void CUtlFixedMemory::Purge() { BlockHeader_t* pFree = pbh; pbh = pbh->m_pNext; - MemAllocSingleton()->Free(pFree); + free(pFree); } m_pBlocks = NULL; m_nAllocationCount = 0; diff --git a/r5dev/public/tier1/utllinkedlist.h b/r5dev/public/tier1/utllinkedlist.h index ef4bcc67..2f4a4c0d 100644 --- a/r5dev/public/tier1/utllinkedlist.h +++ b/r5dev/public/tier1/utllinkedlist.h @@ -447,7 +447,7 @@ void CUtlLinkedList::PurgeAndDeleteElements() for (I i = Head(); i != InvalidIndex(); i = iNext) { iNext = Next(i); - MemAllocSingleton()->Free(Element(i)); + delete Element(i); } Purge(); @@ -1035,15 +1035,6 @@ private: Node_t() {} Node_t(const T& _elem) : elem(_elem) {} - // Have to do it like this instead of 'new' because we have to use the internal memalloc singleton! - static Node_t* Alloc(const T* _elem) - { - Node_t* pNode = MemAllocSingleton()->Alloc(sizeof(Node_t)); - pNode->elem(_elem); - - return pNode; - } - T elem; Node_t* pPrev, * pNext; }; @@ -1055,11 +1046,11 @@ private: if (!pCopyFrom) { - p = MemAllocSingleton()->Alloc(sizeof(Node_t)); + p = new Node_t; } else { - p = Node_t::Alloc(*pCopyFrom); + p = new Node_t(*pCopyFrom); } return p; diff --git a/r5dev/public/tier1/utlmemory.h b/r5dev/public/tier1/utlmemory.h index 109518b4..822c5db7 100644 --- a/r5dev/public/tier1/utlmemory.h +++ b/r5dev/public/tier1/utlmemory.h @@ -331,7 +331,7 @@ public: #ifdef REMEMBER_ALLOC_SIZE_FOR_VALGRIND return m_nCurAllocSize; #else - return (m_pMemory) ? MemAllocSingleton()->GetSize(m_pMemory) : 0; + return (m_pMemory) ? mallocsize(m_pMemory) : 0; #endif } @@ -346,7 +346,7 @@ public: FORCEINLINE void ReAlloc(size_t sz) { - m_pMemory = MemAllocSingleton()->Realloc(m_pMemory, sz); + m_pMemory = (T*)realloc(m_pMemory, sz); RememberAllocSize(sz); } // Grows the memory, so that at least allocated + num elements are allocated @@ -366,7 +366,7 @@ public: // Memory deallocation void Purge() { - MemAllocSingleton()->Free(m_pMemory); + free(m_pMemory); RememberAllocSize(0); m_pMemory = NULL; } @@ -419,7 +419,7 @@ m_nAllocationCount(nInitAllocationCount), m_nGrowSize(nGrowSize) { UTLMEMORY_TRACK_ALLOC(); MEM_ALLOC_CREDIT_CLASS(); - m_pMemory = MemAllocSingleton()->Alloc(m_nAllocationCount * sizeof(T)); + m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T)); } } @@ -496,7 +496,7 @@ void CUtlMemory::Init(int64 nGrowSize /*= 0*/, int64 nInitSize /*= 0*/) { UTLMEMORY_TRACK_ALLOC(); MEM_ALLOC_CREDIT_CLASS(); - m_pMemory = MemAllocSingleton()->Alloc(m_nAllocationCount * sizeof(T)); + m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T)); } } @@ -528,7 +528,7 @@ void CUtlMemory::ConvertToGrowableMemory(int64 nGrowSize) MEM_ALLOC_CREDIT_CLASS(); int64 nNumBytes = m_nAllocationCount * sizeof(T); - T* pMemory = MemAllocSingleton()->Alloc(nNumBytes); + T* pMemory = (T*)malloc(nNumBytes); memcpy(pMemory, m_pMemory, nNumBytes); m_pMemory = pMemory; } @@ -795,13 +795,13 @@ void CUtlMemory::Grow(int64 num) if (m_pMemory) { MEM_ALLOC_CREDIT_CLASS(); - m_pMemory = MemAllocSingleton()->Realloc(m_pMemory, m_nAllocationCount * sizeof(T)); + m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T)); Assert(m_pMemory); } else { MEM_ALLOC_CREDIT_CLASS(); - m_pMemory = MemAllocSingleton()->Alloc(m_nAllocationCount * sizeof(T)); + m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T)); Assert(m_pMemory); } } @@ -832,12 +832,12 @@ inline void CUtlMemory::EnsureCapacity(int64 num) if (m_pMemory) { MEM_ALLOC_CREDIT_CLASS(); - m_pMemory = MemAllocSingleton()->Realloc(m_pMemory, m_nAllocationCount * sizeof(T)); + m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T)); } else { MEM_ALLOC_CREDIT_CLASS(); - m_pMemory = MemAllocSingleton()->Alloc(m_nAllocationCount * sizeof(T)); + m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T)); } } @@ -853,7 +853,7 @@ void CUtlMemory::Purge() if (m_pMemory) { UTLMEMORY_TRACK_FREE(); - MemAllocSingleton()->Free(m_pMemory); + free((void*)m_pMemory); m_pMemory = 0; } m_nAllocationCount = 0; @@ -907,7 +907,7 @@ void CUtlMemory::Purge(int64 numElements) // Allocation count > 0, shrink it down. MEM_ALLOC_CREDIT_CLASS(); - m_pMemory = MemAllocSingleton()->Realloc(m_pMemory, m_nAllocationCount * sizeof(T)); + m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T)); } //----------------------------------------------------------------------------- diff --git a/r5dev/public/tier1/utlstring.h b/r5dev/public/tier1/utlstring.h index 7ce3b8c3..45aafed8 100644 --- a/r5dev/public/tier1/utlstring.h +++ b/r5dev/public/tier1/utlstring.h @@ -825,7 +825,7 @@ private: void FreeHeap() { if (IsHeap() && Heap.m_pchString) - MemAllocSingleton()->Free(Heap.m_pchString); + free(Heap.m_pchString); } // Back to a clean state, but retain the error state. @@ -1205,7 +1205,7 @@ inline void CUtlStringBuilder::SetPtr(char *pchString, size_t nLength) if (!pchString || !nLength) { if (pchString) - MemAllocSingleton()->Free(pchString); // we don't hang onto empty strings. + free(pchString); // we don't hang onto empty strings. return; } diff --git a/r5dev/public/tier1/utlvector.h b/r5dev/public/tier1/utlvector.h index f82f2361..fb1642e1 100644 --- a/r5dev/public/tier1/utlvector.h +++ b/r5dev/public/tier1/utlvector.h @@ -341,22 +341,22 @@ class CUtlVectorUltraConservativeAllocator public: static void* Alloc(size_t nSize) { - return MemAllocSingleton()->Alloc(nSize); + return malloc(nSize); } static void* Realloc(void* pMem, size_t nSize) { - return MemAllocSingleton()->Realloc(pMem, nSize); + return realloc(pMem, nSize); } static void Free(void* pMem) { - MemAllocSingleton()->Free(pMem); + free(pMem); } static size_t GetSize(void* pMem) { - return MemAllocSingleton()->GetSize(pMem); + return mallocsize(pMem); } }; diff --git a/r5dev/tier1/utlstring.cpp b/r5dev/tier1/utlstring.cpp index 6884b965..14b9fc5c 100644 --- a/r5dev/tier1/utlstring.cpp +++ b/r5dev/tier1/utlstring.cpp @@ -816,7 +816,7 @@ char *CUtlStringBuilder::InternalPrepareBuffer(size_t nChars, bool bCopyOld, siz if (bWasHeap && bCopyOld) { // maybe we'll get lucky and get the same buffer back. - pszString = MemAllocSingleton()->Realloc(pszOld, nNewSize + 1); + pszString = (char*)realloc(pszOld, nNewSize + 1); if (!pszString) { SetError(); @@ -830,9 +830,9 @@ char *CUtlStringBuilder::InternalPrepareBuffer(size_t nChars, bool bCopyOld, siz // if we aren't doing a copy, don't use realloc since it will // copy the data if it needs to make a new allocation. if (bWasHeap) - MemAllocSingleton()->Free(pszOld); + free(pszOld); - pszString = MemAllocSingleton()->Alloc(nNewSize + 1); + pszString = (char*)malloc(nNewSize + 1); if (!pszString) { SetError();