Tagged Pointer Strings (2015) (via) Mike Ash digs into a fascinating implementation detail of macOS.
Tagged pointers provide a way to embed a literal value in a pointer reference. Objective-C pointers on macOS are 64 bit, providing plenty of space for representing entire values. If the least significant bit is 1 (the pointer is a 64 bit odd number) then the pointer is "tagged" and represents a value, not a memory reference.
Here's where things get really clever. Storing an integer value up to 60 bits is easy. But what about strings?
There's enough space for three UTF-16 characters, with 12 bits left over. But if the string fits ASCII we can store 7 characters.
Drop everything except a-z A-Z.0-9
and we need 6 bits per character, allowing 10 characters to fit in the pointer.
Apple take this a step further: if the string contains just eilotrm.apdnsIc ufkMShjTRxgC4013
("b" is apparently uncommon enough to be ignored here) they can store 11 characters in that 60 bits!
Recent articles
- ChatGPT in "4o" mode is not running the new features yet - 15th May 2024
- Slop is the new name for unwanted AI-generated content - 8th May 2024
- Weeknotes: more datasette-secrets, plus a mystery video project - 7th May 2024
- Weeknotes: Llama 3, AI for Data Journalism, llm-evals and datasette-secrets - 23rd April 2024
- Options for accessing Llama 3 from the terminal using LLM - 22nd April 2024
- AI for Data Journalism: demonstrating what we can do with this stuff right now - 17th April 2024