are Mnesia tables immutable?

Yariv Sadan <>
Tue Jun 20 00:51:51 CEST 2006


Yes, I should have realized that... I'm still new to Erlang and
functional programming so the concept of immutable data structures
still needs to settle fully in my brain. I have been writing some
parsing code and have been quite paranoid about making horribly
inefficient use of lists.

It did occur to me that it would be useful to have a API for
efficiently handling large strings. It would have similar function
signatures to regular strings, but the implementation would involve
less copying. Does such an API exist?

Regards,
Yariv

On 6/19/06, Håkan Stenholm <> wrote:
> Yariv Sadan wrote:
>
> > Hi,
> >
> > I have a rather basic question: does Erlang's lack of mutable data
> > structures mean that every time you modify a Mnesia (ets) table, the
> > whole table is copied? This sounds very expensive... am I missing
> > something?
> >
> Most data structures are non-mutable but mnesia, ets tables and process
> dictionaries _are_ mutable, data is copied in and out of mnesia/ets when
> accessing - it helps to think of them as erlang processes that one can
> send (write) and recieve (read) messages to/from.
>
> Also note that a non-mutable datastructure doesn't necessarily need to
> copy everything, it's often sufficient, to build a new datastructure
> using mostly old unchanged parts. There are for example tree based data
> structures like gb_trees, that have O(log N)  read and write  costs -
> only a single tree branch is traveresed or updated, when accessing a
> specific tree element.
>
> > Thanks
> > Yariv
> >
>
>



More information about the erlang-questions mailing list