I must be stupid
Sat Jul 9 21:11:18 CEST 2005
Joel Reymont wrote:
> creates just a second without HiPE whereas doing it like this takes I
> don't know how much time (stopped after half an hour or so)
> populate(T, 0) ->
> populate(T, Size) ->
> populate(setelement(Size, T, Size), Size - 1).
> Is there a simple explanation?
Updating a tuple _allways_ creates a new copy of the updated tuple  -
as there is no destructive update.
Attaching a new element to the head of a list, only allocates memory for
In other words a size N tuple in populate/2, will allocate memory for
N*N elements , rather than N elements, as in the populate1/2 call, so
things will obviously go much slower.
: a new copy of the internal pointer array used - the data pointed to
will remain unchanged, only one or more tuple pointers will differ in
the new tuple.
: where N*(N-1) elements of the N*N elements, will later be discarded
by the garbage collector.
> Thanks, Joel
More information about the erlang-questions