immutable data

  • Thread starter Thread starter bbawa1
  • Start date Start date
Hello (e-mail address removed),
What does the term immutable mean? Could you please explain me with
examples.

Google is your friend when looking for definitions....

Enter into google:

define:immutable object
 
"LOLRTFM"

immutable objects are significant because of how the compiler will
deal with them. for instance C# strings are immutable, so if you say

string s = "bl";
foreach (int i=0; i<10; i++)
s += "a";
s+= "h";

the end result is what you think it would be, but the compiler will be
creating lots more temporary strings in between.

"bla", "blaa", "blaaa" ... etc

if strings weren't immutable you wouldn't have as many temporary
objects, but things maintenance behind the scenes would be slower.
When objects are immutable the compiler has more assumptions to work
on and will be faster in the long run (assuming you avoid stuff like
the above). So if something is immutable you should be aware of
temporary object creation getting out of hand.
 
Back
Top