summaryrefslogtreecommitdiff
path: root/src/memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/memory.cpp')
-rw-r--r--src/memory.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/memory.cpp b/src/memory.cpp
index ca64745..7454a2a 100644
--- a/src/memory.cpp
+++ b/src/memory.cpp
@@ -1,9 +1,13 @@
+#if SPECIAL
+#include "main.h"
+#endif
static void
Memory_InitTable(global_memory *GlobalMemory, memory *Memory, uint64 Size, memory_table_list TableName, char *Name, uint64 Block_ElementSize = 0) {
memory_table *Table = &Memory->Slot[TableName];
Table->Name = Name;
Table->Address = (ptrsize *)((uint8 *)GlobalMemory->Address + GlobalMemory->CurrentPosition);
+ // Table->Address = malloc(Size);
Table->Size = Size;
Table->Block_ElementSize = Block_ElementSize;
GlobalMemory->CurrentPosition += Size;
@@ -21,19 +25,21 @@ Memory_Block_AllocateNew(memory *Memory, memory_table_list TableName)
Address_Playhead += Table->Block_ElementSize;
Index++;
}
+ Assert((Address_Playhead - (uint8 *)Table->Address) < Table->Size);
Arbitrary_Zero(Address_Playhead, Table->Block_ElementSize);
return Index;
}
static void *
-Memory_Block_AddressAtIndex(memory *Memory, memory_table_list TableName, uint32 Index, bool32 AssertExists = 1)
+Memory_Block_AddressAtIndex(memory *Memory, memory_table_list TableName, uint32 Index, bool32 AssertExists)
{
memory_table *Table = &Memory->Slot[TableName];
Assert(Table->Block_ElementSize != 0);
uint8 *Address = (uint8 *)Table->Address + (Table->Block_ElementSize * Index);
if (AssertExists)
Assert(*Address != 0);
+ Assert((Address - (uint8 *)Table->Address) < Table->Size);
return (void *)Address;
}
@@ -44,6 +50,7 @@ Memory_Block_LazyIndexAtAddress(memory *Memory, memory_table_list TableName, voi
return ((uint8 *)Address - (uint8 *)Table->Address) / Table->Block_ElementSize;
}
+
static void *
Memory_Block_AllocateAddress(memory *Memory, memory_table_list TableName)
{
@@ -179,11 +186,12 @@ Memory_Block_Bitmap_AllocateNew(project_state *State, memory *Memory, cache_entr
}
static void
-Memory_Cache_Purge(project_data *File, project_state *State, memory *Memory, int32 SingleFrame = -1)
+Memory_Cache_Purge(project_data *File, project_state *State, memory *Memory, int32 SingleFrame)
{
cache_entry *EntryArray = State->Render.Entry;
int c = 0;
int count = Memory->EntryCount;
+ Assert(Memory->EntryCount < 10000);
while (count != 0) {
bool32 ExtraCheck = (SingleFrame == -1) ? 1 : EntryArray[c].TypeInfo_Sub == SingleFrame;
if (EntryArray[c].Type == cache_entry_type_comp &&
@@ -236,6 +244,8 @@ Memory_PushScratch(memory *Memory, uint64 Size) {
uint8 *Address = ((uint8 *)Table->Address + Memory->ScratchPos);
Memory->ScratchPos += Size;
#if DEBUG
+ Assert(Memory->ScratchPos > 0);
+ Assert(Memory->ScratchPos < Table->Size);
Debug.ScratchSize[Debug.ScratchState] = Size;
Debug.ScratchState++;
#endif
@@ -245,6 +255,7 @@ Memory_PushScratch(memory *Memory, uint64 Size) {
static void
Memory_PopScratch(memory *Memory, uint64 Size) {
memory_table *Table = &Memory->Slot[B_ScratchSpace];
+ Assert(Memory->ScratchPos >= Size);
Memory->ScratchPos -= Size;
#if DEBUG
Debug.ScratchState--;
@@ -256,6 +267,7 @@ static void *
Memory_AddressAtOffset(memory *Memory, memory_table_list TableName, uint64 Offset)
{
memory_table *Table = &Memory->Slot[TableName];
+ Assert(Offset < Table->Size);
return (void *)((uint8 *)Table->Address + Offset);
}