Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Insider News
  4. Readonly, Immutable, and Frozen Collections in .NET

Readonly, Immutable, and Frozen Collections in .NET

Scheduled Pinned Locked Moved The Insider News
csharpcomfunctional
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kent Sharkey
    wrote on last edited by
    #1

    NDepend[^]:

    In modern software development, immutability is a powerful concept.

    "I can't change, I can't change. But I'm here in my mold."

    J Richard DeemingR J 3 Replies Last reply
    0
    • K Kent Sharkey

      NDepend[^]:

      In modern software development, immutability is a powerful concept.

      "I can't change, I can't change. But I'm here in my mold."

      J Offline
      J Offline
      jeron1
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • K Kent Sharkey

        NDepend[^]:

        In modern software development, immutability is a powerful concept.

        "I can't change, I can't change. But I'm here in my mold."

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        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

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        K 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          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

          K Offline
          K Offline
          Kent Sharkey
          wrote on last edited by
          #4

          May I suggest as a replacement “Kyle’s Mom”? :-D

          TTFN - Kent

          J 1 Reply Last reply
          0
          • K Kent Sharkey

            NDepend[^]:

            In modern software development, immutability is a powerful concept.

            "I can't change, I can't change. But I'm here in my mold."

            J Offline
            J Offline
            jochance
            wrote on last edited by
            #5

            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?

            O 1 Reply Last reply
            0
            • K Kent Sharkey

              May I suggest as a replacement “Kyle’s Mom”? :-D

              TTFN - Kent

              J Offline
              J Offline
              jochance
              wrote on last edited by
              #6

              ....weeeeellll

              1 Reply Last reply
              0
              • J jochance

                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?

                O Offline
                O Offline
                obermd
                wrote on last edited by
                #7

                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.

                J 1 Reply Last reply
                0
                • O obermd

                  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.

                  J Offline
                  J Offline
                  jochance
                  wrote on last edited by
                  #8

                  So it's more like it can grow the collection without locking anything because it knows everything is new and immutable.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups