[erlang-questions] refactoring a very large record

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Thu Oct 20 17:25:04 CEST 2011


On Thu, Oct 20, 2011 at 16:52, Michael Uvarov <freeakk@REDACTED> wrote:
>> Doesn't the record tuple keep pointers to each element and only updates changes the modified pointers on update?
> It is true only for long binaries.

Consider:

{A, B} = {[1,2,3], 42},
{A, 37}.

Note that A is bound to [1,2,3]. That is, A is a pointer to a list.
The call {A, 37} forms a new tuple, but does not manipulate A. Hence,
since the language is immutable/persistent, we can just reuse the same
pointer in A and we don't have to copy [1,2,3] again. We do need to
allocate space for a two element tuple, {_, _} though so we can store
the pointer to A and 37 in it. This is the worry I have for a
80-element tuple since we need to allocate space for {_,_,...,_} (80
elements) whenever we update it. Reading from it is dirt cheap though,
so it is a clever way if you have data which you need fast indexed
queries on.


-- 
J.



More information about the erlang-questions mailing list