1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | Game_State* gState = (Game_State*)gameMemory->PermanentStorage; transient_state *tranState = (transient_state *)Memory->TransientStorage; {//Movement calculations temporary_memory moveMem = BeginTemporaryMemory(transState); SomeStruct* thing = Malloc(moveMem, someStruct); .......... //Do calculations .......... gState->player->position = resultOfCalculations; EndTemporaryMemory(moveMem); } {//Animation calculations temporary_memory animMem = BeginTemporaryMemory(transState); Animation* animation = Malloc(animMem, Animation); .......... //Find new bone positions from animation calculations .......... gState->player->skeleton = resultingBonePositionsOfSkeleton; EndTemporaryMemory(animMem); } CheckTransMem(transState); //Make sure transient memory is all cleared |
Do I have the right idea? If so, what do you do when you need memory that persists across local temp memory boundaries? Do you allocate a larger memory block outside of all scopes and then just suballocate from that block within the smaller scopes?