From a4c1e537b0cb2540535357d880e46f63b38c134f Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Wed, 5 Oct 2022 23:49:41 -0400 Subject: graph edits; arch rework --- memory.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'memory.cpp') diff --git a/memory.cpp b/memory.cpp index 85c6610..27ac266 100644 --- a/memory.cpp +++ b/memory.cpp @@ -1,18 +1,58 @@ - static void -InitMemoryTable(global_memory *GlobalMemory, memory *Memory, uint64 Size, memory_table_list TableName, char *Name) { +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->Size = Size; + Table->Block_ElementSize = Block_ElementSize; GlobalMemory->CurrentPosition += Size; } -// NOTE(fox): Currently memory acts like simple stack that can only grow forwards. -// Undos/deletes create "holes." Once someone undos/deletes enough to trigger -// the limit or we start caring more about space, I'll revamp the system to -// keep track of free holes and allow those to be returned. +void Memory_Zero(uint8 *Address_Write, uint64 Size) +{ + uint64 i = 0; + while (i < Size) { + *(Address_Write + i) = 0; + i++; + } +} + +static uint32 +Memory_Block_AllocateNew(memory *Memory, memory_table_list TableName) +{ + memory_table *Table = &Memory->Slot[TableName]; + Assert(Table->Block_ElementSize != 0); + bool32 Empty = 0; + uint32 Index = 0; + uint8 *Address_Playhead = (uint8 *)Table->Address; + while (*Address_Playhead != 0) { + Address_Playhead += Table->Block_ElementSize; + Index++; + } + Memory_Zero(Address_Playhead, Table->Block_ElementSize); + *Address_Playhead = 1; + + return Index; +} + +static void * +Memory_Block_AddressAtIndex(memory *Memory, memory_table_list TableName, uint32 Index) +{ + memory_table *Table = &Memory->Slot[TableName]; + Assert(Table->Block_ElementSize != 0); + uint8 *Address = (uint8 *)Table->Address + (Table->Block_ElementSize * Index); + Assert(*Address == 1); + return (void *)Address; +} +static void * +Memory_Block_AllocateAddress(memory *Memory, memory_table_list TableName) +{ + uint16 FileIndex = Memory_Block_AllocateNew(Memory, TableName); + return Memory_Block_AddressAtIndex(Memory, F_File, FileIndex); +} + +#if 0 static void* AllocateMemory(memory *Memory, uint64 Size, memory_table_list TableName) { void *Address; @@ -174,3 +214,4 @@ Memory_RollingBitmap(memory *Memory, source *Source, uint32 FrameToSeek) Debug_Memory_Assert_Cohesion(Memory, Table); return Bitmap; } +#endif -- cgit v1.2.3