Arraylist vs Array vs DataTable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    #1

    Arraylist vs Array vs DataTable

    Wondering the best way of storing my data.

    This is data pulled and stored in the database but a lot of data
    manipulation goes on the client side. I never have to remove items but
    will sometimes clear them all out. It seems to me the best way,
    resource wise, would be just a string array and then use redim when I
    have to add a new "row" of data. Arraylist & datatables seem easier to
    work with, but since I don't need much of the extra's that they add, the
    overhead seems too much price to pay...

    Any thoughts?
    Chris
  • Derek Martin

    #2
    Re: Arraylist vs Array vs DataTable

    It depends a lot on the amount of data you are talking about and such. I
    have excellent results with arraylists, swear by them. I also find
    hashtables quite nice. From an overhead perspective - I have stored
    thousands of objects in an arraylist before and it moves along quite fast.
    If you need to sort, search, etc - super fun there. As for quick access to
    an object, hashtables also have their great moments.

    For situations where a flexible size was important, I suggest arraylist, but
    if you are pulling down data from SQL Server or similar, a datatable will
    provide you a lot of stuff specificly useful to the server.

    HTH
    Derek

    "Chris" <no@spam.com> wrote in message
    news:uXrQurTkFH A.3580@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Wondering the best way of storing my data.
    >
    > This is data pulled and stored in the database but a lot of data
    > manipulation goes on the client side. I never have to remove items but
    > will sometimes clear them all out. It seems to me the best way, resource
    > wise, would be just a string array and then use redim when I have to add a
    > new "row" of data. Arraylist & datatables seem easier to work with, but
    > since I don't need much of the extra's that they add, the overhead seems
    > too much price to pay...
    >
    > Any thoughts?
    > Chris[/color]


    Comment

    • Chris

      #3
      Re: Arraylist vs Array vs DataTable

      Derek Martin wrote:[color=blue]
      > It depends a lot on the amount of data you are talking about and such. I
      > have excellent results with arraylists, swear by them. I also find
      > hashtables quite nice. From an overhead perspective - I have stored
      > thousands of objects in an arraylist before and it moves along quite fast.
      > If you need to sort, search, etc - super fun there. As for quick access to
      > an object, hashtables also have their great moments.
      >
      > For situations where a flexible size was important, I suggest arraylist, but
      > if you are pulling down data from SQL Server or similar, a datatable will
      > provide you a lot of stuff specificly useful to the server.
      >
      > HTH
      > Derek
      >
      > "Chris" <no@spam.com> wrote in message
      > news:uXrQurTkFH A.3580@TK2MSFTN GP09.phx.gbl...
      >[color=green]
      >>Wondering the best way of storing my data.
      >>
      >>This is data pulled and stored in the database but a lot of data
      >>manipulatio n goes on the client side. I never have to remove items but
      >>will sometimes clear them all out. It seems to me the best way, resource
      >>wise, would be just a string array and then use redim when I have to add a
      >>new "row" of data. Arraylist & datatables seem easier to work with, but
      >>since I don't need much of the extra's that they add, the overhead seems
      >>too much price to pay...
      >>
      >>Any thoughts?
      >>Chris[/color]
      >
      >
      >[/color]

      Like I said, I don't need any of the sorting, searching and extras that
      those object give me. Just need a place to store the data while we are
      editing it. I was just kinda curious if there was much overhead there
      was of using ArrayLists vs Arrays. I mean I assume that Arraylist deep
      down is just an array and is just doing a redim when I do an add. So
      why should I hold onto all the overhead for a simple datastore.

      Thanks for your thoughts.
      Chris

      Comment

      • Chris Dunaway

        #4
        Re: Arraylist vs Array vs DataTable

        You will have to pay a price when ReDim'ing an array as that will
        create a 'new' array and copy all the elements to it. If you like
        working with Array semantics, then an ArrayList is a good choice. If
        you know you'll be working with strings, you might take a look at the
        StringCollectio n class in the System.Collecti ons.Specialized namespace.

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Arraylist vs Array vs DataTable

          Chris,

          Is this for a commodore 64, this kind of problems is in my opinion not for
          today anymore (or is should be for a PDA).

          The only problem I can think of is about deleting very much rows in one
          time, because that is a crime in a datatable in VS2002/2003.

          For the rest take the one which makes your program the much readable.

          Data from a database; datatable
          Dynamic array; arraylist
          Static array; array

          Just my thought,

          Cor


          Comment

          • Chris

            #6
            Re: Arraylist vs Array vs DataTable

            Chris Dunaway wrote:[color=blue]
            > You will have to pay a price when ReDim'ing an array as that will
            > create a 'new' array and copy all the elements to it. If you like
            > working with Array semantics, then an ArrayList is a good choice. If
            > you know you'll be working with strings, you might take a look at the
            > StringCollectio n class in the System.Collecti ons.Specialized namespace.
            >[/color]

            If I:

            Dim Array(4) as String
            .... Add Data to Array
            ReDim Preserve Array(5)

            All 5 of the items in Array get copied over when I redim? I didn't know
            that. Do I take the same hit useing an ArrayList.Add() ?

            Chris

            Comment

            • Chris

              #7
              Re: Arraylist vs Array vs DataTable

              Cor Ligthert [MVP] wrote:[color=blue]
              > Chris,
              >
              > Is this for a commodore 64, this kind of problems is in my opinion not for
              > today anymore (or is should be for a PDA).
              >
              > The only problem I can think of is about deleting very much rows in one
              > time, because that is a crime in a datatable in VS2002/2003.
              >
              > For the rest take the one which makes your program the much readable.
              >
              > Data from a database; datatable
              > Dynamic array; arraylist
              > Static array; array
              >
              > Just my thought,
              >
              > Cor
              >
              >[/color]


              "The only problem I can think of is about deleting very much rows in one
              time, because that is a crime in a datatable in VS2002/2003."
              Can you explain this a bit more?


              "Is this for a commodore 64, this kind of problems is in my opinion not
              or today anymore (or is should be for a PDA)."
              I do have to be concerned about memory in this application. It is going
              to be running on TS, so I don't want to eat memory and other resources
              just becauses it is easier....

              Chris

              Comment

              • Derek Martin

                #8
                Re: Arraylist vs Array vs DataTable

                Some good advice Cor, overhead and memory consumption should always be taken
                into consideration, but they aren't make or break like they once were.

                Derek



                "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
                news:%230HF%234 TkFHA.3448@TK2M SFTNGP12.phx.gb l...[color=blue]
                > Chris,
                >
                > Is this for a commodore 64, this kind of problems is in my opinion not for
                > today anymore (or is should be for a PDA).
                >
                > The only problem I can think of is about deleting very much rows in one
                > time, because that is a crime in a datatable in VS2002/2003.
                >
                > For the rest take the one which makes your program the much readable.
                >
                > Data from a database; datatable
                > Dynamic array; arraylist
                > Static array; array
                >
                > Just my thought,
                >
                > Cor
                >[/color]


                Comment

                • Derek Martin

                  #9
                  Re: Arraylist vs Array vs DataTable

                  Like I said, it's your call there really Chris. Arraylist does derive from
                  array on down in the plumbing, but the overhead issue isn't so much with the
                  object's added properties but what you're doing with the data - if you can
                  use the features of Arraylist without Redimming, go for it - I hate
                  redimming just cause I was taught that way for whatever that's worth :-)

                  Derek
                  "Chris" <no@spam.com> wrote in message
                  news:eE1vs1TkFH A.2916@TK2MSFTN GP14.phx.gbl...[color=blue]
                  > Derek Martin wrote:[color=green]
                  >> It depends a lot on the amount of data you are talking about and such. I
                  >> have excellent results with arraylists, swear by them. I also find
                  >> hashtables quite nice. From an overhead perspective - I have stored
                  >> thousands of objects in an arraylist before and it moves along quite
                  >> fast. If you need to sort, search, etc - super fun there. As for quick
                  >> access to an object, hashtables also have their great moments.
                  >>
                  >> For situations where a flexible size was important, I suggest arraylist,
                  >> but if you are pulling down data from SQL Server or similar, a datatable
                  >> will provide you a lot of stuff specificly useful to the server.
                  >>
                  >> HTH
                  >> Derek
                  >>
                  >> "Chris" <no@spam.com> wrote in message
                  >> news:uXrQurTkFH A.3580@TK2MSFTN GP09.phx.gbl...
                  >>[color=darkred]
                  >>>Wondering the best way of storing my data.
                  >>>
                  >>>This is data pulled and stored in the database but a lot of data
                  >>>manipulati on goes on the client side. I never have to remove items but
                  >>>will sometimes clear them all out. It seems to me the best way, resource
                  >>>wise, would be just a string array and then use redim when I have to add
                  >>>a new "row" of data. Arraylist & datatables seem easier to work with,
                  >>>but since I don't need much of the extra's that they add, the overhead
                  >>>seems too much price to pay...
                  >>>
                  >>>Any thoughts?
                  >>>Chris[/color]
                  >>
                  >>
                  >>[/color]
                  >
                  > Like I said, I don't need any of the sorting, searching and extras that
                  > those object give me. Just need a place to store the data while we are
                  > editing it. I was just kinda curious if there was much overhead there was
                  > of using ArrayLists vs Arrays. I mean I assume that Arraylist deep down
                  > is just an array and is just doing a redim when I do an add. So why
                  > should I hold onto all the overhead for a simple datastore.
                  >
                  > Thanks for your thoughts.
                  > Chris[/color]


                  Comment

                  • Robin Tucker

                    #10
                    Re: Arraylist vs Array vs DataTable

                    You don't need to, no. The array is probably better than the array list
                    with < 1000 items or so, depending on how you use it. The arraylist is just
                    allocating more storage than you need so in the average case it doesn't need
                    to ReDim when adding an item.

                    I tend to store database objects in hashtables, keyed on the database
                    primary key of course. If you are wiping the entire table though and don't
                    care about keys, then I would suggest an arraylist. It will scale better
                    than a basic array and isn't any more difficult to use. The only thing is
                    boxing/unboxing, which might slow you down a tiny bit - but not in any
                    noticable way I don't think.

                    [color=blue]
                    >
                    > Like I said, I don't need any of the sorting, searching and extras that
                    > those object give me. Just need a place to store the data while we are
                    > editing it. I was just kinda curious if there was much overhead there was
                    > of using ArrayLists vs Arrays. I mean I assume that Arraylist deep down
                    > is just an array and is just doing a redim when I do an add. So why
                    > should I hold onto all the overhead for a simple datastore.
                    >
                    > Thanks for your thoughts.
                    > Chris[/color]


                    Comment

                    Working...