3 ms·
You'd probably only need two or three bits to pack a controller id. Depending on how much memory the system has, and and things like data alignment, you can fin
by cbhl 12y ago
You'd probably only need two or three bits to pack a controller id. Depending on how much memory the system has, and and things like data alignment, you can find some bits in the pointer that will always have a specific value (say, zero). Then, you can store the ID in those bits, and mask them away when you actually want the pointer.
Edit: You probably shouldn't do this in new code, but in the context of memory-constrained C code it's a nice hack.
- United857 12y agoInteresting enough, the current 64-bit ObjC runtime does something similar, with so-called "tagged pointers". https://www.mikeash.com/pyblog/friday-qa-2013-09-27-arm64-and-you.html https://www.mikeash.com/pyblog/friday-qa-2013-09-27-arm64-an...
- jheriko 12y agoright, but then why can't you take that same opportunity to pull your pointer out and replace it with a zero to avoid it being free'd ?