Handmade Hero»Forums»Code
19 posts
Slow ZeroStruct call
Edited by jeringa on
Isn't the fact that when you create a brand new arena via VirtualAlloc the reason it was so slow?
As the very first time you touch the page the Windows COW system would be forced to map the page for real
and at the end of the sim you ditch the memory again

Would be easy to test...
Call ZeroStruct twice and only time the second call
504 posts
Slow ZeroStruct call
Edited by ratchetfreak on
Or first write a 0 byte to the first address per allocated page in the arena and then time the clear.

Though a better way to fix that would be to let the thread keep an initialized arena and pass it down when the task with memory is executed.

aka let the thread hold the arena which puts it in a perfect position to be reused by the next task which needs memory.
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Slow ZeroStruct call
Yeah, that is a good point - it could be that the VirtualAlloc call doesn't take much time but it's page faulting in the ZeroAlloc because Windows hasn't mapped it yet, which would argue I should have gone ahead and done the test of having threads have their own scratch arena... we should try that on the next stream.

- Casey