I have to use so many String arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rsaikamesh
    New Member
    • Oct 2006
    • 20

    I have to use so many String arrays

    Hi All,

    In my c++ application, I need to use 60 string arrays with the size of 16. If I create this much of arrays, will the performance of my application be affected?
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    So you are creating something like:

    Code:
    char strings[60][16];
    This is 60 * 16 bytes of memory, or 960 bytes of memory - in other words, practically nothing. It is relatively large compared to other variables such as a single int, but I don't think it will be big enough to seriously affect your program's performance time.

    Comment

    • rsaikamesh
      New Member
      • Oct 2006
      • 20

      #3
      Originally posted by Ganon11
      So you are creating something like:

      Code:
      char strings[60][16];
      This is 60 * 16 bytes of memory, or 960 bytes of memory - in other words, practically nothing. It is relatively large compared to other variables such as a single int, but I don't think it will be big enough to seriously affect your program's performance time.
      I have to create like the following:

      string str1[16];
      .
      .
      .
      string str60[16];

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        What you are creating here are 60 arrays of 16 strings. Are you sure this is what you require? I had assumed you meant you needed 60 strings that would hold 16 characters each, not 60 string arrays of 16 strings each.

        Comment

        • rsaikamesh
          New Member
          • Oct 2006
          • 20

          #5
          Originally posted by Ganon11
          What you are creating here are 60 arrays of 16 strings. Are you sure this is what you require? I had assumed you meant you needed 60 strings that would hold 16 characters each, not 60 string arrays of 16 strings each.
          yes, I am sure about that. now please say, whether the performance will be affected or not?

          Comment

          • Ganon11
            Recognized Expert Specialist
            • Oct 2006
            • 3651

            #6
            Well, this will be 60 arrays * 16 entries * 4 bytes, which is 3840 bytes - still not a huge amount. But might I suggest instead of using

            Code:
            str1[16];
            str2[16];
            ...
            str60[16];
            you may consider using a 2D array:

            Code:
            str[60][16];

            Comment

            • rsaikamesh
              New Member
              • Oct 2006
              • 20

              #7
              Originally posted by Ganon11
              Well, this will be 60 arrays * 16 entries * 4 bytes, which is 3840 bytes - still not a huge amount. But might I suggest instead of using

              Code:
              str1[16];
              str2[16];
              ...
              str60[16];
              you may consider using a 2D array:

              Code:
              str[60][16];
              Thank you very much!!!

              Comment

              • Banfa
                Recognized Expert Expert
                • Feb 2006
                • 9067

                #8
                Originally posted by Ganon11
                Well, this will be 60 arrays * 16 entries * 4 bytes.
                Strictly speaking if using ~4kbytes of memory is a performance issue is platform dependent.

                For instance on a PC with 1GByte of RAM then 4kbytes of memory is negligable, however on a microprocessor with 32kbyte of RAM 4kbyte is 12.5% of available memory and could be very significant.

                Comment

                • Extremist
                  New Member
                  • Jan 2007
                  • 94

                  #9
                  How about just using
                  Code:
                  string str60[60];
                  It would work in C++,

                  would there be a performance issue?

                  Comment

                  Working...