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. Memory allocation for List

Memory allocation for List

Scheduled Pinned Locked Moved .NET (Core and Framework)
performancequestion
5 Posts 4 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

    How the memory is allocated in heap for a dynamically growing List. while creating a new object the number of bytes required for that type is allocated in heap. How this is working if that class has a dynamic list???

    My small attempt...

    L L A 3 Replies Last reply
    0
    • S sujithkumarsl

      How the memory is allocated in heap for a dynamically growing List. while creating a new object the number of bytes required for that type is allocated in heap. How this is working if that class has a dynamic list???

      My small attempt...

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

      Find memory allocation detail in following links... http://www.codeguru.com/columns/dotnet/article.php/c6593/[^] Read following section in above link Allocation and Garbage Collection Details For generalized information about memory allocation by .NET http://www.dotnet-guide.com/exploring-different-stages-of-memory-management-in-net.html[^] HTH

      Jinal Desai - LIVE Experience is mother of sage....

      1 Reply Last reply
      0
      • S sujithkumarsl

        How the memory is allocated in heap for a dynamically growing List. while creating a new object the number of bytes required for that type is allocated in heap. How this is working if that class has a dynamic list???

        My small attempt...

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        a List does not store its items, all it stores are references to those items. Basically it stores them in an array. When the array gets full, a new array is allocated, twice the size, and its content (the references!) is copied to the new array. Objects never grow. They have a fixed size in memory. Assuming Car and Wheel are classes, when a Car object has four Wheel objects, it holds 4 references to those Wheel instances, which are separate objects. If Wheel where a struct (hence a value type, not a reference type), the Car would hold memory to store 4 Wheel instances all the time, whether you initialize them or not. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read formatted code with indentation, so please use PRE tags for code snippets.


        I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


        1 Reply Last reply
        0
        • S sujithkumarsl

          How the memory is allocated in heap for a dynamically growing List. while creating a new object the number of bytes required for that type is allocated in heap. How this is working if that class has a dynamic list???

          My small attempt...

          A Offline
          A Offline
          Anshul R
          wrote on last edited by
          #4

          It is like a linked list(not really.. but for the memory allocation part). It can have any number of items while memory is free. It is like using malloc function

          L 1 Reply Last reply
          0
          • A Anshul R

            It is like a linked list(not really.. but for the memory allocation part). It can have any number of items while memory is free. It is like using malloc function

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            pranav95 wrote:

            It is like a linked list

            Not at all. A linked list would consist of individual items, each holding one or two pointers to its logical neighbors, and would imply: a separate memory block for each item, no overall memory requirement (except maybe for a head node and a tail node), and certainly no memory requirement larger than the item size itself. A .NET collection is based on an array, most additions do not require any memory requirement at all, and the array's capacity grows by doubling it, which may cause it to become located in the "large object heap" and may even cause fragmentation and out-of-memory situations one would not have with a linked list; OTOH being array-based has advantages, e.g. it allows for an O(1) indexing. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read formatted code with indentation, so please use PRE tags for code snippets.


            I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


            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