3 ms·
Another way to implement fat pointers is to keep the pointer representation the same but have another structure like an interval tree that stores a map of point
by rwmj 7y ago
Another way to implement fat pointers is to keep the pointer representation the same but have another structure like an interval tree that stores a map of pointers to the extra information on bounds. That's how I implemented Bounds Checking GCC back in the day: https://www.doc.ic.ac.uk/~phjk/BoundsChecking.html https://www.doc.ic.ac.uk/~phjk/BoundsChecking.html It has the advantage that pointers remain compatible with code that wasn't specially compiled to know about fat pointers (such as system libraries).
- rocqua 7y agoSeems like that would hurt memory locality, with a commensurate increase in cache-misses.
- rwmj 7y agoWell Bounds Checking GCC had a huge overhead anyway (making code about 3-5 times slower) so memory locality wasn't our primary concern.
- wahern 7y agoThat's basically how Intel MPX works, https://en.wikipedia.org/wiki/Intel_MPX as well as TinyCC's Bounds Check, https://bellard.org/tcc/tcc-doc.html#Bounds which cites the aforementioned GCC patch. I think AddressSanitizer uses a shadow mapping structure more similar to Valgrind. Although your point about performance still stands. Intel MPX is dead--support removed from GCC, IIRC, because of hints Intel was abandoning it. We'll never know how well it could have been optimized in practice. I think ultimately we simply need proper fat pointers, but those might not become ubiquitous (in the sense of becoming a de facto standard part of shared, C-based platform ABIs) until we see 128-bit native pointers.