fix: c++ issues in pl_memory.h
This commit is contained in:
parent
61699c7b97
commit
10ea3a7ce8
18
pl_memory.h
18
pl_memory.h
@ -125,12 +125,12 @@ void pl_pool_allocator_free (plPoolAllocator*, void* pItem);
|
|||||||
|
|
||||||
typedef struct _plTempAllocator
|
typedef struct _plTempAllocator
|
||||||
{
|
{
|
||||||
size_t szSize;
|
size_t szSize; // size in bytes of current working buffer
|
||||||
size_t szOffset;
|
size_t szOffset; // offset into pcBuffer
|
||||||
char* pcBuffer;
|
char* pcBuffer; // current working buffer (starts as acStackBuffer)
|
||||||
char acStackBuffer[PL_MEMORY_TEMP_STACK_SIZE];
|
char acStackBuffer[PL_MEMORY_TEMP_STACK_SIZE];
|
||||||
char** ppcMemoryBlocks;
|
char** ppcMemoryBlocks;
|
||||||
size_t szMemoryBlockCount;
|
size_t szMemoryBlockCount; // current number working heap alloc blocks
|
||||||
size_t szMemoryBlockCapacity;
|
size_t szMemoryBlockCapacity;
|
||||||
size_t szCurrentBlockSizes;
|
size_t szCurrentBlockSizes;
|
||||||
size_t szNextBlockSizes;
|
size_t szNextBlockSizes;
|
||||||
@ -347,6 +347,7 @@ pl_temp_allocator_alloc(plTempAllocator* ptAllocator, size_t szSize)
|
|||||||
ptAllocator->ppcMemoryBlocks = (char**)PL_MEMORY_ALLOC(sizeof(char*) * (ptAllocator->szMemoryBlockCapacity + 1));
|
ptAllocator->ppcMemoryBlocks = (char**)PL_MEMORY_ALLOC(sizeof(char*) * (ptAllocator->szMemoryBlockCapacity + 1));
|
||||||
memset(ptAllocator->ppcMemoryBlocks, 0, (sizeof(char*) * (ptAllocator->szMemoryBlockCapacity + 1)));
|
memset(ptAllocator->ppcMemoryBlocks, 0, (sizeof(char*) * (ptAllocator->szMemoryBlockCapacity + 1)));
|
||||||
memcpy(ptAllocator->ppcMemoryBlocks, ppcOldBlocks, sizeof(char*) * ptAllocator->szMemoryBlockCapacity);
|
memcpy(ptAllocator->ppcMemoryBlocks, ppcOldBlocks, sizeof(char*) * ptAllocator->szMemoryBlockCapacity);
|
||||||
|
PL_MEMORY_FREE(ppcOldBlocks);
|
||||||
ptAllocator->szMemoryBlockCapacity++;
|
ptAllocator->szMemoryBlockCapacity++;
|
||||||
ptAllocator->ppcMemoryBlocks[ptAllocator->szMemoryBlockCount] = (char*)PL_MEMORY_ALLOC(szNewBlockSize);
|
ptAllocator->ppcMemoryBlocks[ptAllocator->szMemoryBlockCount] = (char*)PL_MEMORY_ALLOC(szNewBlockSize);
|
||||||
ptAllocator->szSize = szNewBlockSize;
|
ptAllocator->szSize = szNewBlockSize;
|
||||||
@ -369,7 +370,10 @@ pl_temp_allocator_alloc(plTempAllocator* ptAllocator, size_t szSize)
|
|||||||
ptAllocator->ppcMemoryBlocks = (char**)PL_MEMORY_ALLOC(sizeof(char*) * (ptAllocator->szMemoryBlockCapacity + 1));
|
ptAllocator->ppcMemoryBlocks = (char**)PL_MEMORY_ALLOC(sizeof(char*) * (ptAllocator->szMemoryBlockCapacity + 1));
|
||||||
memset(ptAllocator->ppcMemoryBlocks, 0, (sizeof(char*) * (ptAllocator->szMemoryBlockCapacity + 1)));
|
memset(ptAllocator->ppcMemoryBlocks, 0, (sizeof(char*) * (ptAllocator->szMemoryBlockCapacity + 1)));
|
||||||
memcpy(ptAllocator->ppcMemoryBlocks, ppcOldBlocks, sizeof(char*) * ptAllocator->szMemoryBlockCapacity);
|
memcpy(ptAllocator->ppcMemoryBlocks, ppcOldBlocks, sizeof(char*) * ptAllocator->szMemoryBlockCapacity);
|
||||||
|
PL_MEMORY_FREE(ppcOldBlocks);
|
||||||
ptAllocator->szMemoryBlockCapacity++;
|
ptAllocator->szMemoryBlockCapacity++;
|
||||||
|
if(ptAllocator->szMemoryBlockCount == 0) // special case
|
||||||
|
PL_MEMORY_FREE(ptAllocator->ppcMemoryBlocks[ptAllocator->szMemoryBlockCount]);
|
||||||
ptAllocator->ppcMemoryBlocks[ptAllocator->szMemoryBlockCount] = (char*)PL_MEMORY_ALLOC(szNewBlockSize);
|
ptAllocator->ppcMemoryBlocks[ptAllocator->szMemoryBlockCount] = (char*)PL_MEMORY_ALLOC(szNewBlockSize);
|
||||||
ptAllocator->szSize = szNewBlockSize;
|
ptAllocator->szSize = szNewBlockSize;
|
||||||
ptAllocator->pcBuffer = ptAllocator->ppcMemoryBlocks[ptAllocator->szMemoryBlockCount];
|
ptAllocator->pcBuffer = ptAllocator->ppcMemoryBlocks[ptAllocator->szMemoryBlockCount];
|
||||||
@ -434,9 +438,9 @@ pl__temp_allocator_sprintf_va(plTempAllocator* ptAllocator, const char* cPFormat
|
|||||||
|
|
||||||
pRequestedMemory = pl_temp_allocator_alloc(ptAllocator, n + 1);
|
pRequestedMemory = pl_temp_allocator_alloc(ptAllocator, n + 1);
|
||||||
memset(pRequestedMemory, 0, n + 1);
|
memset(pRequestedMemory, 0, n + 1);
|
||||||
pl_vnsprintf(pRequestedMemory, n + 1, cPFormat, args);
|
pl_vnsprintf((char*)pRequestedMemory, n + 1, cPFormat, args);
|
||||||
|
|
||||||
return pRequestedMemory;
|
return (char*)pRequestedMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
@ -449,7 +453,7 @@ pl_temp_allocator_sprintf(plTempAllocator* ptAllocator, const char* cPFormat, ..
|
|||||||
pRequestedMemory = pl__temp_allocator_sprintf_va(ptAllocator, cPFormat, argptr);
|
pRequestedMemory = pl__temp_allocator_sprintf_va(ptAllocator, cPFormat, argptr);
|
||||||
va_end(argptr);
|
va_end(argptr);
|
||||||
|
|
||||||
return pRequestedMemory;
|
return (char*)pRequestedMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user