Readonly, Immutable, and Frozen Collections in .NET
-
Quote:
She said, "You're strange, but don't change, and I let her"
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
-
Kent Sharkey wrote:
I can't change, I can't change.
Thanks - now I've got Saddam from "South Park - The Movie" singing in my head! :laugh:
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Kent Sharkey wrote:
I can't change, I can't change.
Thanks - now I've got Saddam from "South Park - The Movie" singing in my head! :laugh:
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
May I suggest as a replacement “Kyle’s Mom”? :-D
TTFN - Kent
-
How would you use immutable collection in thread safe scenario? The creating a new instance of the collection (presumably - it says it works like string)... but in the thread safe scenarios I may have dealt with, it's been that I wanted to have a single shared collection across those thread instances. Maybe I misunderstand how it works and that's just 'taken care of' with a locking object and a 'root collection' under the hood?
-
May I suggest as a replacement “Kyle’s Mom”? :-D
TTFN - Kent
-
How would you use immutable collection in thread safe scenario? The creating a new instance of the collection (presumably - it says it works like string)... but in the thread safe scenarios I may have dealt with, it's been that I wanted to have a single shared collection across those thread instances. Maybe I misunderstand how it works and that's just 'taken care of' with a locking object and a 'root collection' under the hood?
Yes and no. For mutable objects the locking has to occur at runtime. If, however, you tell the compiler that the object is immutable it can skip outputting the locking code and assume there won't be changes to the object at runtime. Locking is an expensive operation.
-
Yes and no. For mutable objects the locking has to occur at runtime. If, however, you tell the compiler that the object is immutable it can skip outputting the locking code and assume there won't be changes to the object at runtime. Locking is an expensive operation.