Thu Mar 25 23:37:18 CET 1999
> I have an algorithm which requires a recursive function to have access to a
> fairly large fixed-size array of constants (probably a tuple, indexable with
> element/2 since that should have O(1) performance, and it won't need to be
> anywhere near 64k elements long). My question is, if I simply declare this
> tuple as a value within the function, will it be recreated for each
> recursive call to the function, or is Erlang smart enough to set it up once
> (at compile time, even, as pre-initialized static data, since it is never
> modified) and keep it around for subsequent usage?
Well, first of all. If you want to store lots of data I recommend using
ets-tables, see the man-page for ets. They give you O(1) performance.
Also, under the user-contrib area you'll find an "efficient dynamically
expanding array package for heap-based storage". I haven't used it
myself but Ulf Wiger (ulf.wiger@REDACTED) can probably give you
details about the performance. See:
Next, there have been problems (in the past at least) when you try to
compile a tuple of size > 256. The work around has been to create a
list of elements and then use the BIF list_to_tuple/1 .
Finally, yes if you don't modify your tuple. Erlang only passes
around the reference to it.
> Incidentally, why is there no recognizer guard for funs? ...
There is: function(F)
More information about the erlang-questions