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. General Programming
  3. .NET (Core and Framework)
  4. Value type in Stack???

Value type in Stack???

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpdata-structuresperformancequestion
3 Posts 3 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.
  • S Offline
    S Offline
    sujithkumarsl
    wrote on last edited by
    #1

    according to my current knowledge in .net memory management the value types are stored in stack and reference types are stored in managed heap. Form this, its clear that the object of a class will be saved in heap. Then where will be the memory allocated for the value type member of that class??

    My small attempt...

    L L 2 Replies Last reply
    0
    • S sujithkumarsl

      according to my current knowledge in .net memory management the value types are stored in stack and reference types are stored in managed heap. Form this, its clear that the object of a class will be saved in heap. Then where will be the memory allocated for the value type member of that class??

      My small attempt...

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The entire object will be stored on the heap including any 'value type' members.

      It's time for a new signature.

      1 Reply Last reply
      0
      • S sujithkumarsl

        according to my current knowledge in .net memory management the value types are stored in stack and reference types are stored in managed heap. Form this, its clear that the object of a class will be saved in heap. Then where will be the memory allocated for the value type member of that class??

        My small attempt...

        L Offline
        L Offline
        LookSharp
        wrote on last edited by
        #3

        For a method's local variables, value types are indeed stored on the stack and reference types on the heap. Reference types are a little confusing, however, because they are really stored in two parts: the reference, which is stored on the stack just like a value type, and the 'body', which is stored on the heap. Now, lets look at the body of a type (reference type or value type). Reference types and value types can have fields of both types. The fields of a type are (effectively) concatenated together. So the body of a type is the concatenation of the contained value types and the references to the contained reference types. And this body is 'a chunk of memory' which is stored somewhere - on the stack (if its the body of a value type), on the heap (if its the body of a reference type) .. or nestled inside the body of some other type (if its a field in another type). So, it may be more useful to think of value types as being stored 'where they are declared' instead of thinking of them as being stored on the stack, while reference types have their reference stored where the variable is declared, and its body is always stored on the heap.

        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