I'm a recovering programmer who has been designing video games since the 1980s, doing things that seem baroquely hardcore in retrospect, like writing Super Nintendo games entirely in assembly language. These days I use whatever tools are the most fun and give me the biggest advantage.
james.hague @ gmail.com
Where are the comments?
Finally: Data Structure Constants in ErlangHere's a simple Erlang function to enclose some text in a styled paragraph, returning a deep list:
- Every time
parawas called, the two constant lists (a.k.a. strings) were created, which is to say that there weren't true data structure constants in Erlang.
- Each string was built-up, letter by letter, via a series of BEAM virtual machine instructions. The larger the constant, the more code there was to generate it, and the more time it took to generate.
- Because a new version of each string was created for each
paracall, there was absolutely no sharing of data. If
parawas called 200 times, 400 strings were created (200 of each). Remember, too, that each element of a list/string in 32-bit Erlang is 8 bytes. Doing the math on this example is mildly unsettling: 22 characters * 8 bytes per character * 200 instances = 35,200 bytes of "constant" string data.
- As a result of more data being created, garbage collection occurred more frequently and took longer (because there was more live data).
And now, finally, as of the December 2007 R12B release, true data structure constants are supported in BEAM.