mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Replace memalloc calls for Valve container types
Utilize new malloc system using the conventional approach, see commit 708a2495.
This commit is contained in:
parent
d0bdbcd2b0
commit
ae52aa0081
@ -251,7 +251,7 @@ void CUtlBlockMemory<T, I>::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<T, I>::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;
|
||||
}
|
||||
|
||||
|
@ -345,7 +345,7 @@ void CUtlFixedMemory<T>::Purge()
|
||||
{
|
||||
BlockHeader_t* pFree = pbh;
|
||||
pbh = pbh->m_pNext;
|
||||
MemAllocSingleton()->Free(pFree);
|
||||
free(pFree);
|
||||
}
|
||||
m_pBlocks = NULL;
|
||||
m_nAllocationCount = 0;
|
||||
|
@ -447,7 +447,7 @@ void CUtlLinkedList<T, S, ML, I, M>::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<Node_t>(sizeof(Node_t));
|
||||
pNode->elem(_elem);
|
||||
|
||||
return pNode;
|
||||
}
|
||||
|
||||
T elem;
|
||||
Node_t* pPrev, * pNext;
|
||||
};
|
||||
@ -1055,11 +1046,11 @@ private:
|
||||
|
||||
if (!pCopyFrom)
|
||||
{
|
||||
p = MemAllocSingleton()->Alloc<Node_t>(sizeof(Node_t));
|
||||
p = new Node_t;
|
||||
}
|
||||
else
|
||||
{
|
||||
p = Node_t::Alloc(*pCopyFrom);
|
||||
p = new Node_t(*pCopyFrom);
|
||||
}
|
||||
|
||||
return p;
|
||||
|
@ -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<T>(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<T>(m_nAllocationCount * sizeof(T));
|
||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
@ -496,7 +496,7 @@ void CUtlMemory<T, I>::Init(int64 nGrowSize /*= 0*/, int64 nInitSize /*= 0*/)
|
||||
{
|
||||
UTLMEMORY_TRACK_ALLOC();
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
m_pMemory = MemAllocSingleton()->Alloc<T>(m_nAllocationCount * sizeof(T));
|
||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
@ -528,7 +528,7 @@ void CUtlMemory<T, I>::ConvertToGrowableMemory(int64 nGrowSize)
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
|
||||
int64 nNumBytes = m_nAllocationCount * sizeof(T);
|
||||
T* pMemory = MemAllocSingleton()->Alloc<T>(nNumBytes);
|
||||
T* pMemory = (T*)malloc(nNumBytes);
|
||||
memcpy(pMemory, m_pMemory, nNumBytes);
|
||||
m_pMemory = pMemory;
|
||||
}
|
||||
@ -795,13 +795,13 @@ void CUtlMemory<T, I>::Grow(int64 num)
|
||||
if (m_pMemory)
|
||||
{
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
m_pMemory = MemAllocSingleton()->Realloc<T>(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<T>(m_nAllocationCount * sizeof(T));
|
||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
||||
Assert(m_pMemory);
|
||||
}
|
||||
}
|
||||
@ -832,12 +832,12 @@ inline void CUtlMemory<T, I>::EnsureCapacity(int64 num)
|
||||
if (m_pMemory)
|
||||
{
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
m_pMemory = MemAllocSingleton()->Realloc<T>(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<T>(m_nAllocationCount * sizeof(T));
|
||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
@ -853,7 +853,7 @@ void CUtlMemory<T, I>::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<T, I>::Purge(int64 numElements)
|
||||
|
||||
// Allocation count > 0, shrink it down.
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
m_pMemory = MemAllocSingleton()->Realloc<T>(m_pMemory, m_nAllocationCount * sizeof(T));
|
||||
m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -341,22 +341,22 @@ class CUtlVectorUltraConservativeAllocator
|
||||
public:
|
||||
static void* Alloc(size_t nSize)
|
||||
{
|
||||
return MemAllocSingleton()->Alloc<void*>(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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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<char>(nNewSize + 1);
|
||||
pszString = (char*)malloc(nNewSize + 1);
|
||||
if (!pszString)
|
||||
{
|
||||
SetError();
|
||||
|
Loading…
x
Reference in New Issue
Block a user