15 ms·
Nice stories. I don't understand how exactly the solution for 'All Signs Point to "No-No"' works. He says he packs the controller id into the pointer slot, allr
by oliveoil 17y ago
Nice stories. I don't understand how exactly the solution for 'All Signs Point to "No-No"' works. He says he packs the controller id into the pointer slot, allright, but doesn't he also say that the framework will free() the pointer later?
- pavlov 17y agoI was wondering about that as well. Maybe there's an invalid memory region on this platform which free() knows about and will silently ignore (for example the first N bytes of the address space), and the controller IDs happen to be in that range? Seems unlikely, but I can't think of anything else to explain it...
- Retric 17y agoIt turns out that the event system would take it upon itself to free() the event's void pointer after processing the event. You could set the pointer's value to be the controler's ID and then set it to null while you handle the event, and before you pass it down the chain. Or, the OS might be ok (and do nothing) when trying to free memory that's in the middle of a block of allocated memory.
- vidarh 17y agoIf so his original approach of putting the controller id in a region allocated for the purpose and putting the pointer to that region in the event would have worked just as well and he wouldn't need to do what he did.
- vidarh 17y agoHe mentioned a "multi heap" system. If he was using an allocator that knew which address ranges he'd allocated from, it's not unlikely it'd work. Alternatively if he used an allocator that'd do suitable sanity checks - free() will need to be able to find the length of the block, for example, and if the length doesn't make sense...
- vidarh 17y agoPresumably he was depending on the allocator gracefully ignoring arguments to free() that were invalid.
- bradtgmurray 17y agoPerhaps their allocator only allocated and free'd memory in 4-byte aligned blocks, and would mask out the lower bits to make pointers align to those blocks before freeing them? If you had an allocator like this, you could use the addresses 0 through 3, and presumably the deallocator would mask these all down to zero, and then do a check to make sure it doesn't free 0, and end up doing nothing.