Add memory allocation tracking data to debug state
This commit is contained in:
@@ -15,7 +15,9 @@ enum DebugCallCount
|
||||
|
||||
typedef struct DebugState
|
||||
{
|
||||
i32 totalMemoryAllocated;
|
||||
i32 *callCount;
|
||||
|
||||
/* Debug strings rendered in top left corner */
|
||||
char debugStrings[256][64];
|
||||
i32 numDebugStrings;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define DENGINE_MATH_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "Dengine/Common.h"
|
||||
|
||||
#define squared(x) (x * x)
|
||||
|
||||
@@ -3,8 +3,16 @@
|
||||
|
||||
#include <Windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Dengine/Common.h"
|
||||
#include "Dengine/Debug.h"
|
||||
|
||||
// TODO(doyle): Create own custom memory allocator
|
||||
#define PLATFORM_MEM_ALLOC(num, type) \
|
||||
CAST(type *) platform_memoryAlloc(num * sizeof(type))
|
||||
#define PLATFORM_MEM_FREE(ptr, bytes) \
|
||||
platform_memoryFree(CAST(void *) ptr, bytes)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -12,15 +20,38 @@ typedef struct
|
||||
i32 size;
|
||||
} PlatformFileRead;
|
||||
|
||||
i32 platform_readFileToBuffer(const char *const filePath,
|
||||
PlatformFileRead *file);
|
||||
// TODO(doyle): numBytes in mem free is temporary until we create custom
|
||||
// allocator since we haven't put in a system to track memory usage per
|
||||
// allocation
|
||||
inline void platform_memoryFree(void *data, i32 numBytes)
|
||||
{
|
||||
if (data) free(data);
|
||||
|
||||
#ifdef DENGINE_DEBUG
|
||||
GLOBAL_debugState.totalMemoryAllocated -= numBytes;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
inline void *platform_memoryAlloc(i32 numBytes)
|
||||
{
|
||||
void *result = calloc(1, numBytes);
|
||||
|
||||
#ifdef DENGINE_DEBUG
|
||||
if (result)
|
||||
GLOBAL_debugState.totalMemoryAllocated += numBytes;
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void platform_closeFileRead(PlatformFileRead *file)
|
||||
{
|
||||
if (file->buffer)
|
||||
{
|
||||
free(file->buffer);
|
||||
}
|
||||
PLATFORM_MEM_FREE(file->buffer, file->size);
|
||||
}
|
||||
|
||||
|
||||
i32 platform_readFileToBuffer(const char *const filePath,
|
||||
PlatformFileRead *file);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user