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. C#
  4. Array and related collections.

Array and related collections.

Scheduled Pinned Locked Moved C#
data-structuresalgorithmsperformancehelpquestion
6 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.
  • H Offline
    H Offline
    HAHAHA_NEXT
    wrote on last edited by
    #1

    Making my application i have suddently got and evil optimization question about "What are the internals of the array list" :sigh:. Does any of you know if it is based on a linked list or on an array. Also do you know where i can get my hand on a Simple Linked List or a Binary Tree. Thank you for help.

    J H 2 Replies Last reply
    0
    • H HAHAHA_NEXT

      Making my application i have suddently got and evil optimization question about "What are the internals of the array list" :sigh:. Does any of you know if it is based on a linked list or on an array. Also do you know where i can get my hand on a Simple Linked List or a Binary Tree. Thank you for help.

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      An ArrayList is an array that grows dynamically by recreating the array (often doubling the size) everytime the bounds are surpassed. As far as binary trees go, I suggest you take a peak at the MSDN article[^] regarding data structures. Part 3[^] of the article shows off some trees, including the source for a binary tree in C#. --------------------------- He who knows that enough is enough will always have enough. -Lao Tsu

      1 Reply Last reply
      0
      • H HAHAHA_NEXT

        Making my application i have suddently got and evil optimization question about "What are the internals of the array list" :sigh:. Does any of you know if it is based on a linked list or on an array. Also do you know where i can get my hand on a Simple Linked List or a Binary Tree. Thank you for help.

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        As Judah said, it uses a new array that typically doubles whenever the Capacity is reached. To note, the ArrayList is used internally by many collections, so don't think you can escape it so easily! ;)

        Microsoft MVP, Visual C# My Articles

        H 1 Reply Last reply
        0
        • H Heath Stewart

          As Judah said, it uses a new array that typically doubles whenever the Capacity is reached. To note, the ArrayList is used internally by many collections, so don't think you can escape it so easily! ;)

          Microsoft MVP, Visual C# My Articles

          H Offline
          H Offline
          HAHAHA_NEXT
          wrote on last edited by
          #4

          Thank both of you. I have another little question. What is the perforamce loss due to the type casting of array list elements. If my array list contains the same type elemets (or which share the same base class), could i use something equivalent to templates in C++. Thank again. Anton.

          H 1 Reply Last reply
          0
          • H HAHAHA_NEXT

            Thank both of you. I have another little question. What is the perforamce loss due to the type casting of array list elements. If my array list contains the same type elemets (or which share the same base class), could i use something equivalent to templates in C++. Thank again. Anton.

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            An ArrayList stores objects, so if you add reference types to the list, there's really no performance hit (1 to 2 extra instructions are required to cast, and optionally store, your type, but that's negligible). If you store value types, there is a slight performance hit because value types must be boxed and unboxed to store as an object. This is one of many reasons why generics will be great to have in the upcoming .NET Framework 2.0. Then you can declare a new list of value types, like List<int> ints = new List<int>();. This (un)boxing is typically not too big a problem if you don't use it a lot and don't need to milk your app for performance for every last drop. If you do, then you might consider implementing your own ArrayList-like class, implementing all the same interfaces (for the best support) and keep an array of whatever value type you need. Grow it when needs be, just like the ArrayList would.

            Microsoft MVP, Visual C# My Articles

            H 1 Reply Last reply
            0
            • H Heath Stewart

              An ArrayList stores objects, so if you add reference types to the list, there's really no performance hit (1 to 2 extra instructions are required to cast, and optionally store, your type, but that's negligible). If you store value types, there is a slight performance hit because value types must be boxed and unboxed to store as an object. This is one of many reasons why generics will be great to have in the upcoming .NET Framework 2.0. Then you can declare a new list of value types, like List<int> ints = new List<int>();. This (un)boxing is typically not too big a problem if you don't use it a lot and don't need to milk your app for performance for every last drop. If you do, then you might consider implementing your own ArrayList-like class, implementing all the same interfaces (for the best support) and keep an array of whatever value type you need. Grow it when needs be, just like the ArrayList would.

              Microsoft MVP, Visual C# My Articles

              H Offline
              H Offline
              HAHAHA_NEXT
              wrote on last edited by
              #6

              In this case i will keep it, since making changes later would be much easier. Thank you.

              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