Manipulating Data Structures

Christopher Clark <>
Fri Jun 2 17:05:37 CEST 2000


> The question is about data structures and the copy overhead
> of their modification.
> Let's say you have in Perl something like
>         $record = {
>             "language" => 'Java',
>             "status" => 'overhyped',
>             "usage" => 'with care',
>             "samples" => [ $prog1, $prog2 ]     %% each $progX is a
> 200kByte data chunk
>        }
> Now, how do I most effeciently do something like
>         $record->{status} = "dead".
> 
> So to put it simple: how do I update large data structures without
> running into useless copy operations of the whole structure.

  Well, I am also a newbie, but the ``proper'' way to do this seems to
be...

============

-record(programming_language, {language, status, usage, samples = []}).

Java = #programming_language{language = java,
                             status = overhyped,
                             usage = with_care,
                             samples = [Prog1, Prog2]}.

New_Java = Java#programming_language{status = dead}.

============

  (Note to self: in real life, use shorter record names.)

  I would assume, having not gone over the interpreter source code, that
this will be as efficient as it seems (i.e. only changing the one
field).  Am I right, o seasoned Erlang practitioners?

-- 
Christopher Clark <>

  We hadn't changed the principles, we hadn't changed who we are, we
hadn't changed anything except how we presented it.  We said `Code
Morphing software' and, snap, we got funding.              -- Doug Laird



More information about the erlang-questions mailing list