PushBuffer question

(I'm one or two videos behind)
Casey just introduced a PushBuffer structure to act as a command buffer for the renderer.

He mentioned that this can be used to store objects of various size.
But once you stop using objects of uniform size, it then becomes very hard to search the structure, no? You can't do random access anymore, it's more like a linked list.
How can we do sorting efficiently on this structure? (I'm mentioning sorting because one of the goals of the buffer is to handle correct z sorting).

thanks!

Edited by Fred on
It's easy to make this kind of like an array since we pre allocated space? Not sure but if all of the structure size are all the same you can access X by doing

startoflinkedlist + sizeof(struct buffer) + index

I might be wrong tho, if more then one structure type pushed into the linkedlist or it gets push some where else in the memory which means the addresses won't be in order, then it won't work.

Edited by popcorn on
As long as we store something that allows us to get back to the start of an individual structure, we can easily sort it. So, for example, instead of storing an index as if it were an array of same-size structs, we can just store a byte index that says where the struct starts, and that handles everything. It's basically the same as just using pointers, only we don't need 64-bits to store it, we just use 32 because we know everything is based of the same base pointer in memory.

- Casey