4 ms·
I 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 f
by pavlov 17y ago
I 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...