Use static_casts instead of C style, remove unnecessary casts

This commit is contained in:
Robert Müller 2023-11-26 13:32:47 +01:00
parent 7a142df580
commit 591c08cf34

View file

@ -8,15 +8,12 @@
// allocates a new chunk to be used // allocates a new chunk to be used
void CHeap::NewChunk() void CHeap::NewChunk()
{ {
// allocate memory
char *pMem = (char *)malloc(sizeof(CChunk) + CHUNK_SIZE);
if(!pMem)
return;
// the chunk structure is located in the beginning of the chunk // the chunk structure is located in the beginning of the chunk
// init it and return the chunk // init it and return the chunk
CChunk *pChunk = (CChunk *)pMem; CChunk *pChunk = static_cast<CChunk *>(malloc(sizeof(CChunk) + CHUNK_SIZE));
pChunk->m_pMemory = (char *)(pChunk + 1); if(!pChunk)
return;
pChunk->m_pMemory = static_cast<char *>(static_cast<void *>(pChunk + 1));
pChunk->m_pCurrent = pChunk->m_pMemory; pChunk->m_pCurrent = pChunk->m_pMemory;
pChunk->m_pEnd = pChunk->m_pMemory + CHUNK_SIZE; pChunk->m_pEnd = pChunk->m_pMemory + CHUNK_SIZE;
pChunk->m_pNext = nullptr; pChunk->m_pNext = nullptr;
@ -75,14 +72,14 @@ void CHeap::Clear()
void *CHeap::Allocate(unsigned Size, unsigned Alignment) void *CHeap::Allocate(unsigned Size, unsigned Alignment)
{ {
// try to allocate from current chunk // try to allocate from current chunk
char *pMem = (char *)AllocateFromChunk(Size, Alignment); void *pMem = AllocateFromChunk(Size, Alignment);
if(!pMem) if(!pMem)
{ {
// allocate new chunk and add it to the heap // allocate new chunk and add it to the heap
NewChunk(); NewChunk();
// try to allocate again // try to allocate again
pMem = (char *)AllocateFromChunk(Size, Alignment); pMem = AllocateFromChunk(Size, Alignment);
} }
return pMem; return pMem;