[video output=day160 member=cmuratori stream_platform=twitch stream_username=handmade_hero project=code title="Basic General Purpose Allocation" vod_platform=youtube id=MyGsWY6dezE annotator=debiatan annotator=ZedZull]
[00:00:13][Recap and plan for the day]
[00:01:54][Plan for today: Writing our own general-purpose memory allocator]
[00:04:12][Ode to stack memory allocation]
[00:05:33][The asset system needs a more sophisticated memory allocator]
[00:06:45][Closer look at asset eviction and memory fragmentation (blackboard)]
[00:10:41][Overview of our approach]
[00:13:01][Thinking of our available memory in terms of free fragments]
[00:14:25][Merging contiguous free blocks]
[00:16:12][We won't be performing small allocations]
[00:16:50][Every block will keep information of neighboring blocks]
[00:18:43][A possible way of implementing the allocation operation]
[00:24:12][We can call EvictAssetsAsNecessary from inside AcquireAssetMemory!]
[00:28:44][Modifying AcquireAssetMemory to work with our own memory]
[00:36:08][Evicting assets to make room for a new one]
[00:37:19][Keeping track of the location of our assets]
[00:40:46][Doubly linked list of memory blocks]
[00:50:12][FindBlockForSize]
[00:52:26][Conditionally splitting the memory block used to store an asset as a function of its remaining capacity]
[00:56:35][Recovering memory blocks inside ReleaseAssetMemory]
[00:58:15][Q&A][:speech]
[00:59:40][@jameswidman][Given that this is an optimization problem, it seems like we'll want to have a system for profiling asset use and eviction (and check its output periodically as the game and assets grow over the next year or so). Should this be on the agenda in the near term?]
[01:01:13][@graeme7][I'm not clear on what happens in the else when we fail to find a block, could you go over it?]
[01:03:43][@constantinopol][Why do we need to check the remaining size > threshold ? Why not just use the remaining size if it satisfies the request size?]
[01:06:06][@snafusel][How come this memory management system is strictly limited to game assets and not other things as well?]
[01:06:41][@gasto5][What will the GUI handle? (Answered at 01:11:18)]
[01:06:52][@grumpygiant256][If this were a commercial project, would it make sense to use malloc instead here, or write your own anyway for managing assets?]
[01:09:30][@gasto5][Any possibility of using Markov Chains for the game or game engine?]
[01:09:47][@mojobojo][It's looking like Vulkan, if it gets released in a timely manner, is going to be a good choice for hardware rendering. I just read that you have control over all memory to avoid any unknown allocations "Explicit memory management in Vulkan allows applications to use custom allocation strategies. For example to allocate all memory up-front and avoid any allocations during rendering"]
[01:11:08][@blah238][Have you thought about having a "prefab" asset that people could use to make more complex assets, like a whole house with functional doors?]
[01:11:19][@gasto5][(Referring to Q at 01:06:41) The GUI mentioned in the TODO list]
[01:11:48][@constantinopol][You keep saying "split the block in half" What do you mean? 'Size = Size/2'?]
[01:13:36][@mojobojo][(Referring to Q at 01:09:47) This is where I read it from: http://blog.imgtec.com/powervr/trying-out-the-new-vulkan-graphics-api-on-powervr-gpus]
[01:15:07][@insofaras][Will the debug GUI have a cool console like Quake/Unreal?]
[/video]
