-- U5lQrlUVgXtGbmO/Jn0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Fri, 2005-12-09 at 14:52 +0900, petermichaux / yahoo.com wrote: > Thanks for all the responses. > > Could someone describe how symbols are stored in memory? Integers. They're indices into an array of unique string values, which is accompanied by a hash table of string values to indices. When a string is converted to a symbol, the string is looked up in the hash table. If no entry is found, the string value is appended to the array, and its index is recorded to the hash table. If an entry already exists, that index (the symbol) is simply returned. When a symbol is converted to a string, its index is looked up in the array and that string value returned. The values of two symbols can also be compared directly to determine whether their associated strings are equal. This is much faster than comparing two strings. If you are storing the same string value multiple places, it may also save memory to represent it with a symbol. Be careful, however. That array never shrinks, so every unique string value you turn into a symbol stays around until your program exits. It's best to reserve symbols for situations where you expect a bounded number of unique string values. -mental -- U5lQrlUVgXtGbmO/Jn0 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQBDmTFtcUNIGiXCc4MRAjosAJ0S1a1LIN6axKE/v0ne8NQV5c0dTQCgoVcr 4Vutop12CVvBA2wDGp3hpGo fR -----END PGP SIGNATURE----- -- U5lQrlUVgXtGbmO/Jn0--