static void InitMemoryTable(global_memory *GlobalMemory, memory *Memory, uint64 Size, memory_table_list TableName, char *Name) { memory_table *Table = &Memory->Slot[TableName]; Table->Name = Name; Table->Address = (uint64 *)((uint8 *)GlobalMemory->Address + GlobalMemory->CurrentPosition); Table->Size = Size; GlobalMemory->CurrentPosition += Size; } static void* AllocateMemory(memory *Memory, uint64 Size, memory_table_list TableName) { void *Address; memory_table *Table = &Memory->Slot[TableName]; if (Table->CurrentPosition + Size > Table->Size) { return NULL; } Address = (uint64 *)((uint8 *)Table->Address + Table->CurrentPosition); Table->CurrentPosition += Size; return Address; } // Returns 0-1 range wherever Pointer is in relation to StartingPointer to Size*Amount. static real32 Memory_NormalizedPosition(void *StartingPointer, uint32 Amount, uint32 Size, void *Pointer) { real32 Result = 0; uint64 TotalSize = Amount*Size; uint64 PointerLocationSize = (uint8 *)Pointer - (uint8 *)StartingPointer; Result = (real32)PointerLocationSize / (real32)TotalSize; return Result; } static void Debug_Memory_Assert_Cohesion(memory *Memory, memory_table *Table) { #if DEBUG for (uint32 i = 0; i < Table->NumberOfPointers; i++) { cached_bitmap *CurrentBitmap = &Memory->Bitmap[i]; Assert(CurrentBitmap->Data); for (uint32 a = 0; a < Table->NumberOfPointers; a++) { if (a == i) { continue; } cached_bitmap *OtherBitmap = &Memory->Bitmap[a]; if (OtherBitmap->Data == CurrentBitmap->Data) { Assert(0); } } } #else #endif }