Quickie Memory Consumption Q ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Samishii23
    New Member
    • Sep 2009
    • 246

    Quickie Memory Consumption Q ?

    Lets say I have 30 variables, int, string mostly, or more...

    Would it be better for me to make 30 separate instances of a variable. Or an array with [30] slots?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    What do you define as "better"?
    Faster response...
    More human-readable code...
    Smaller memory footprint...
    Ease of coding...

    For 30 variables of any standard type such as int, string and so on...
    It really won't matter. It's not like the days of the Commodore-64 where you only had 64 *K* of memory.

    If you had 30,000 it might be a different story.
    Hey, there is a good test...
    Programmaticall y generate 30,000 ints and strings and give them all values and see how much memory that takes.
    Then create a couple arrays of 30,000 and assign them values and see how much that takes.

    Whatever the difference in memory usage is for those two tests... You application will see 1/1000th of that difference.

    Comment

    • Samishii23
      New Member
      • Sep 2009
      • 246

      #3
      I am worried about amount of memory used mostly. Speed of the application isn't really my big worry.

      I thought it may have been more of a difference then what you describe.

      Comment

      • Minion
        Recognized Expert New Member
        • Dec 2007
        • 108

        #4
        As far as memory consumption goes it's not tied so much to the number fo variables (unless your getting into the thousands), but rather the content of the application. If you have a large number of forms or a dataset that must be kept in memory this will eat up memory far faster than variable declaration.

        Comment

        • alexis4
          New Member
          • Dec 2009
          • 113

          #5
          re: Quickie Memory Consumption Q ?

          If they are logically connected, then a class or a structure would be fine. If not, then you should keep them separate. Still you can store them in a class, but this would make your code more difficult to read. If we are talking about same variables (for example 5 pictureBoxes), then a class array is recommended for my part, because if later on you decide that for example you need two buttons for each pictureBox, it would be uncomfortable to have 15 event handlers in one form instead of three! Besides that, you do not know if later on the 5 boxes become 10. So one important factor is to have a stretchable code, especially in bigger projects.

          Comment

          • Samishii23
            New Member
            • Sep 2009
            • 246

            #6
            Well, basicly my application is going to be heavily string based data, not that that is uncommon, its just I'm still brainstorming ideas on how to store, and retrieve the data ( the reason for the post ). Also will be using alot of images.

            Comment

            • PRR
              Recognized Expert Contributor
              • Dec 2007
              • 750

              #7
              What exactly are the variables? int and strings? I guess you are facing a design issue here. Try a OO (object oriented) approach here. Maybe group together strings and int that are related in a structure or class. Have a main class that has objects of the other classes and structures. Also you can look into interface and inheritance. This approach will make your code less complex and easy to read, maintain and understand.

              Comment

              • Samishii23
                New Member
                • Sep 2009
                • 246

                #8
                Well. The very first way I was storing the data was in a class. Each data set had its own class. To give you an idea of what I'm working with, I have 10 classes. ATM, I don't have this data set fully complete, and .cs file is 242 KB large. Thats just the data. Not functions or anything. This the general layout of the variables...

                Code:
                public class cData1 {
                // 3 of each the next variables
                public readonly int dPts[44];
                public readonly string dTitle[44];
                public readonly string dIcon[44];
                public readonly string dDisc[44][];
                }
                I want to put all the data into XML format, though the XML portion of C# is... Kinda bloated. Heh.

                Comment

                Working...