memory - Arrays implementation in erlang -


my question is, how arrays implemented in erlang, opposed lists.

with immutable types doing things like,

move ([x | xs], ys) ->     [x | ys].  ls = move([1,2,3], [2,3,4]) 

would take constant mem in heap, since reference work.

but same stuff in arrays

move (a1, a2) ->     array:set(0, array:get(0,a1),a2).  a1 = array:from_list([1,2,3]). a2 = array:from_list([0,2,3,4]). a3 = move(a1,a2). 

will move here use size proportional a2 or able in constant space arrays?

to (hopefully) clear things little. remember in erlang all data immutable! profoundly affects how manipulate data.

the array module builds structure of nested tuples array slots containing data @ same level. size of each tuple 10 array access have o(lg10(n)). using nested structure common in languages immutable data. could keep array in flat tuple give fast reads, writes become slow , memory hogging large arrays/tuples every write entail creating new tuple. using tree structure means less data created in write.

how move/2 function affects memory usage depends little on whether writing used or unused slot in array. if slot in use resultant memory usage same. if writing unused slot may need grow array mean more memory used.

this same list case.

it depends on whether there remaining references old data structure.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -