4 ms·
Tagged pointers really have nothing to do with late binding. They're useful anywhere you have a data that is sometimes small enough to fit within a single point
by mikeash 11y ago
Tagged pointers really have nothing to do with late binding. They're useful anywhere you have a data that is sometimes small enough to fit within a single pointer-sized chunk, and sometimes isn't. Strings are a good example of this: short strings can be tagged pointers, and long strings can be dynamically allocated. As another commenter mentioned, some C++ implementations use tagged pointers for std::string.
Another example might be a big number library, where numbers smaller than the pointer size could be implemented as tagged pointers, and larger numbers would be dynamically allocated. A C++ big number library could easily do this.
Whether it's worth the cost depends on how expensive memory allocation is, how expensive pointer indirection is, how many objects are able to fit within a tagged pointer, and how expensive the tag check is. Typically the answers are, a lot, a lot, a lot, and a lot. And dynamism doesn't change the answer much.
- jheriko 11y agoerm. why are you even using a pointer if its not late-binding? this is what static, stack, scopes and global variables are for with references as needed...