What is the most compact way to encode/save DNS names in memory?
For example, storing "www.google.com" as a string in .NET will result in the object being encoded as UTF-16, and it will consume twice as much memory as plain ASCII... but for the purpose of storing DNS names, ASCII is overkill.
The only characters that are needed are:
- A..Z (case insensitive)
- 0..9
- Hyphen
- underscore
- period
- Asterisk (not legal DNS, but used in ACLs such as *.google.com) always as a leading character, never elsewhere.
A total of 40 characters.. which fits within single byte with plenty room to spare.
My code golf question/challenge is what is the most compact way to store a string of characters in memory and maximizing in memory storage?
The inspiration for this challenge came from this blog entry.