Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
taitruong committed Dec 19, 2014
1 parent 0945e0f commit a9be2e2
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ In general and as mentioned by Odersky the idiomatic way is to use immutable and

## Performance and Memory consumption

What if you add or remove elements from a list? Prepending an element to an immutable list does internally no create a new list. Instead when you prepend an element to a list [a new pointer is created](http://stackoverflow.com/questions/2123290/why-is-the-operator-for-list-deprecated-in-scala#comment2062773_2123428) and links the element with the existing list. The List class does not offer an append operation - in fact there was an [+ operation but it was deprecated](http://stackoverflow.com/questions/2123290/why-is-the-operator-for-list-deprecated-in-scala). As stated [here](http://www.artima.com/pins1ed/next-steps-in-scala.html#step8):
What if you add or remove elements from a list? Prepending an element to an immutable list does internally not create a new list. Instead when you prepend an element to a list [a new pointer is created](http://stackoverflow.com/questions/2123290/why-is-the-operator-for-list-deprecated-in-scala#comment2062773_2123428) and links the element with the existing list. The List class does not offer an append operation - in fact there was an [+ operation but it was deprecated](http://stackoverflow.com/questions/2123290/why-is-the-operator-for-list-deprecated-in-scala). As stated [here](http://www.artima.com/pins1ed/next-steps-in-scala.html#step8):
> '... Class List does not offer an append operation, because the time it takes to append to a list grows linearly with the size of the list, whereas prepending with :: takes constant time. Your options if you want to build a list by appending elements is to prepend them, then when you're done call reverse; or use a ListBuffer, a mutable list that does offer an append operation, and when you're done call toList.'
There is another Stack Overflow [discussion about the performance and memory consumption](http://stackoverflow.com/questions/1308682/scala-mutable-vs-immutable-object-performance-outofmemoryerror) on Map dealing with one million elements.
Expand Down

0 comments on commit a9be2e2

Please sign in to comment.