Array size limits

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

    #16
    Re: Array size limits

    "Wei Li" <liwei_guard-pub@yahoo.com> writes:[color=blue]
    > I don't know how ANSI C says. But the stacksize of a program in runtime is
    > limited by Opterating System. So that C compiler always doesn't give out an
    > compile time error.
    >
    > If you are on Linux, you can use "limit" command to show the limits and use
    > "limit stacksize 1000000" to change them. I think your program will work OK
    >
    > "Carol Depore" <nobody@nowhere .com> wrote in message
    > news:lmn7j09msk s2q00nihpps23sn o0olk1hl6@4ax.c om...[color=green]
    > > How do I determine the maximum array size?
    > >
    > > For example, int a[10000] works, but a[10000000] does not (run time
    > > error).
    > >
    > > Thank you.[/color][/color]

    Wei Li: Please don't top-post.

    Top-posting means writing your new material first, followed by the
    quoted article to which you're responding. It makes it difficult to
    follow the discussion, especially when (almost) everyone else
    bottom-posts, as I'm doing there. (You should also trim anything
    that's not relevant to your response, though in this case the previous
    article was short enough that quoting the whole thing is probably ok.)

    Thanks.

    --
    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.

    Comment

    • Mabden

      #17
      Re: Array size limits


      "Wei Li" <liwei_guard-pub@yahoo.com> wrote in message
      news:10j9udisiu bej02@corp.supe rnews.com...[color=blue]
      > I don't know how ANSI C says. But the stacksize of a program in runtime[/color]
      is[color=blue]
      > limited by Opterating System. So that C compiler always doesn't give out[/color]
      an[color=blue]
      > compile time error.
      >
      > If you are on Linux, you can use "limit" command to show the limits and[/color]
      use[color=blue]
      > "limit stacksize 1000000" to change them. I think your program will work[/color]
      OK[color=blue]
      > after change the limit.
      >
      > "Carol Depore" <nobody@nowhere .com> wrote in message
      > news:lmn7j09msk s2q00nihpps23sn o0olk1hl6@4ax.c om...[color=green]
      > > How do I determine the maximum array size?
      > >
      > > For example, int a[10000] works, but a[10000000] does not (run time
      > > error).
      > >[/color][/color]

      It's the same with recursion. I attempted a simple factorial program (below)
      and it crapped out at 39! and even then I think the result was wrong (it was
      a while ago, so I don't remember whether it worked right or not) but I
      needed something much bigger, so I moved on. I recall believing the fault
      was in the recursion, not the size of the value, but it was many years ago.

      -------------------------------------------
      #include <stdio.h>
      #include <stdlib.h>

      double fact (int n);

      void main(int argc, char **argv)
      {
      int n;
      double factorial=1;

      n = atoi (argv[1]);
      fact (n);
      }

      double fact (int n)
      {
      static double value=1;

      if (n > 1)
      value = n * fact (n-1);

      printf ("%3.d! = %.0f \n", n, value);

      return (value);
      }
      -------------------------------------------

      --
      Mabden




      Comment

      • Carol Depore

        #18
        Re: Array size limits


        Wow, I think a little tiny light bulb has been lit in my head! Thanks
        to all of you!

        In summary,
        - There are TWO areas for array allocation, a stack area and a global
        area.
        - When my little test program uses the stack (by default), the array
        is limited to about int a[500000]. (the stack limit probably can be
        increased, but I'll learn that later).
        - However, if I use the global area, by "static int", then my array
        can be much larger. My test program below, with a[20000000], worked
        fine!!

        #include <stdio.h>

        //#define NNN 600000
        #define NNN 20000000

        int main() {
        long i;
        static int a[NNN];
        printf("Start\n ");
        for (i=0;i<NNN;i++) {
        printf("%i\n",i );
        a[i] = 1;
        }
        }


        Thanks again, to all of you!


        Comment

        • Old Wolf

          #19
          Re: Array size limits

          Carol Depore <nobody@nowhere .com> wrote:[color=blue]
          >
          > Anyway, I'm still confused about how large a simple int array can be.[/color]

          Short answer: it depends, and you can't tell in advance.
          [color=blue]
          > I understand what Jack and Ben said about the Standard guaranteeing
          > at least int a[32767], but I don't understand why I can't have an
          > array of int a[600000], especially since I have 311MB of unused memory
          > on my machine, and I thought the machine would allow programs up to
          > 4GB.[/color]

          Your machine probably has restrictions on how big "automatic"
          objects can be (ie. when you go int a[NNN] inside a function).
          if you want to use up all of your actual memory then you should
          try dynamic allocation, which has the advantage that you can
          handle errors nicely instead of just getting a runtime error:
          [color=blue]
          > #include <stdio.h>
          >
          > //#define NNN 600000
          > #define NNN 500000
          >
          > int main() {
          > long i;
          > int a[NNN];
          > for (i=0;i<NNN;i++) {
          > printf("%i\n",i );
          > a[i] = 1;
          > }
          > }[/color]

          #include <stdio.h>
          #include <stdlib.h>

          #define NNN 600000

          int main(void) {
          long i;
          int *a = malloc(NNN * sizeof *a);
          if (a == NULL) {
          printf("not enough memory.\n");
          return EXIT_FAILURE;
          }
          for (i = 0; i < NNN; i++) {
          printf("%i\n", i);
          a[i] = 1;
          }
          free(a); /* releases the memory for other applications */
          }

          Comment

          • Wei Li

            #20
            Re: Array size limits

            Thanks! I will be careful next time :P

            "Keith Thompson" <kst-u@mib.org> wrote in message
            news:lnvfeyrhlz .fsf@nuthaus.mi b.org...[color=blue]
            > "Wei Li" <liwei_guard-pub@yahoo.com> writes:[color=green]
            > > I don't know how ANSI C says. But the stacksize of a program in[/color][/color]
            runtime is[color=blue][color=green]
            > > limited by Opterating System. So that C compiler always doesn't give[/color][/color]
            out an[color=blue][color=green]
            > > compile time error.
            > >
            > > If you are on Linux, you can use "limit" command to show the limits and[/color][/color]
            use[color=blue][color=green]
            > > "limit stacksize 1000000" to change them. I think your program will work[/color][/color]
            OK[color=blue][color=green]
            > >
            > > "Carol Depore" <nobody@nowhere .com> wrote in message
            > > news:lmn7j09msk s2q00nihpps23sn o0olk1hl6@4ax.c om...[color=darkred]
            > > > How do I determine the maximum array size?
            > > >
            > > > For example, int a[10000] works, but a[10000000] does not (run time
            > > > error).
            > > >
            > > > Thank you.[/color][/color]
            >
            > Wei Li: Please don't top-post.
            >
            > Top-posting means writing your new material first, followed by the
            > quoted article to which you're responding. It makes it difficult to
            > follow the discussion, especially when (almost) everyone else
            > bottom-posts, as I'm doing there. (You should also trim anything
            > that's not relevant to your response, though in this case the previous
            > article was short enough that quoting the whole thing is probably ok.)
            >
            > Thanks.
            >
            > --
            > Keith Thompson (The_Other_Keit h) kst-u@mib.org[/color]
            <http://www.ghoti.net/~kst>[color=blue]
            > San Diego Supercomputer Center <*>[/color]
            <http://users.sdsc.edu/~kst>[color=blue]
            > We must do something. This is something. Therefore, we must do this.[/color]


            Comment

            • Dan Pop

              #21
              Re: Array size limits

              In <10j9udisiubej0 2@corp.supernew s.com> "Wei Li" <liwei_guard-pub@yahoo.com> writes:
              [color=blue]
              >I don't know how ANSI C says. But the stacksize of a program in runtime is
              >limited by Opterating System. So that C compiler always doesn't give out an
              >compile time error.
              >
              >If you are on Linux, you can use "limit" command to show the limits and use
              >"limit stacksize 1000000" to change them. I think your program will work OK
              >after change the limit.[/color]

              How do you know the OP's array was automatically allocated?

              Dan
              [color=blue]
              >"Carol Depore" <nobody@nowhere .com> wrote in message
              >news:lmn7j09ms ks2q00nihpps23s no0olk1hl6@4ax. com...[color=green]
              >> How do I determine the maximum array size?
              >>
              >> For example, int a[10000] works, but a[10000000] does not (run time
              >> error).[/color][/color]

              --
              Dan Pop
              DESY Zeuthen, RZ group
              Email: Dan.Pop@ifh.de

              Comment

              • grv575

                #22
                Re: Array size limits

                Please use google groups to read news. It syntax highlights
                everything so threads aren't difficult to follow either way. Btw, I
                prefer "topposting " since you don't have to scroll past what's already
                been said in the thread.

                I'm really surprised though that noone has pointed out so far that
                most compilers will have some kind of flag or directive to allow a
                larger stack size which is the most likely wall you're running in to
                (all this talk of standards and no real solutions).

                Keith Thompson <kst-u@mib.org> wrote in message news:<lnvfeyrhl z.fsf@nuthaus.m ib.org>...[color=blue]
                > "Wei Li" <liwei_guard-pub@yahoo.com> writes:[color=green]
                > > I don't know how ANSI C says. But the stacksize of a program in runtime is
                > > limited by Opterating System. So that C compiler always doesn't give out an
                > > compile time error.
                > >
                > > If you are on Linux, you can use "limit" command to show the limits and use
                > > "limit stacksize 1000000" to change them. I think your program will work OK
                > >
                > > "Carol Depore" <nobody@nowhere .com> wrote in message
                > > news:lmn7j09msk s2q00nihpps23sn o0olk1hl6@4ax.c om...[color=darkred]
                > > > How do I determine the maximum array size?
                > > >
                > > > For example, int a[10000] works, but a[10000000] does not (run time
                > > > error).
                > > >
                > > > Thank you.[/color][/color]
                >
                > Wei Li: Please don't top-post.
                >
                > Top-posting means writing your new material first, followed by the
                > quoted article to which you're responding. It makes it difficult to
                > follow the discussion, especially when (almost) everyone else
                > bottom-posts, as I'm doing there. (You should also trim anything
                > that's not relevant to your response, though in this case the previous
                > article was short enough that quoting the whole thing is probably ok.)
                >
                > Thanks.[/color]

                Comment

                • Randy Howard

                  #23
                  Re: Array size limits

                  In article <10ja93e5qk9012 3@corp.supernew s.com>, liwei_guard-pub@yahoo.com
                  says...[color=blue]
                  > Thanks! I will be careful next time :P
                  >
                  > "Keith Thompson" <kst-u@mib.org> wrote in message
                  > news:lnvfeyrhlz .fsf@nuthaus.mi b.org...[/color]

                  [snip discussion about top-posting]

                  You just did it again. Better be more careful. :-)

                  --
                  Randy Howard
                  To reply, remove FOOBAR.

                  Comment

                  • Flash Gordon

                    #24
                    Re: Array size limits

                    On 1 Sep 2004 07:59:26 -0700
                    grv575@hotmail. com (grv575) wrote:
                    [color=blue]
                    > Please use google groups to read news.[/color]

                    Google is an on-line service that performs badly as a news reader. Many
                    people read groups off-line for a number of good reasons, including
                    dial-up connections where you pay per minute for being connected.
                    [color=blue]
                    > It syntax highlights
                    > everything so threads aren't difficult to follow either way.[/color]

                    Yes they are. My news reader colour-codes quoted text, but to understand
                    you post I had to scroll to the bottom to see what you were replying to
                    then scroll back up to see your response. Posting after the quoted
                    material means that anyone with a decent news reader (and a lot of
                    people with horrible things which just about allow one to read news) can
                    run through a group by just hitting the space bar, only having to do
                    something else when replying.
                    [color=blue]
                    > Btw, I
                    > prefer "topposting " since you don't have to scroll past what's already
                    > been said in the thread.[/color]

                    That is why one snips material that is not relevant to the reply,
                    summarising if appropriate.
                    [color=blue]
                    > I'm really surprised though that noone has pointed out so far that
                    > most compilers will have some kind of flag or directive to allow a
                    > larger stack size which is the most likely wall you're running in to
                    > (all this talk of standards and no real solutions).[/color]

                    The most likely solution is using malloc and this has been suggested.
                    [color=blue]
                    > Keith Thompson <kst-u@mib.org> wrote in message
                    > news:<lnvfeyrhl z.fsf@nuthaus.m ib.org>...[/color]

                    <snip>
                    --
                    Flash Gordon
                    Sometimes I think shooting would be far too good for some people.
                    Although my email address says spam, it is real and I read it.

                    Comment

                    • Default User

                      #25
                      Re: Array size limits

                      grv575 wrote:
                      [color=blue]
                      > Please use google groups to read news.[/color]

                      The absolute worst newsreader/news provider? Why?
                      [color=blue]
                      > Btw, I
                      > prefer "topposting " since you don't have to scroll past what's already
                      > been said in the thread.[/color]

                      If you want to participate in this newsgroup, you'll be advised to
                      follow the posting conventions. Many, like me, will killfile you if you
                      don't stop top-posting.

                      Search the web for the many, many arguments against top-posting.



                      Brian Rodenborn

                      Comment

                      • Keith Thompson

                        #26
                        Re: Array size limits

                        grv575@hotmail. com (grv575) writes:[color=blue]
                        > Please use google groups to read news. It syntax highlights
                        > everything so threads aren't difficult to follow either way. Btw, I
                        > prefer "topposting " since you don't have to scroll past what's already
                        > been said in the thread.[/color]

                        The nearly universal convention of this newsgroup is to avoid
                        top-posting. There are good reasons for this, which you can see in
                        other responses to your article. The best reason, though, is that
                        it's the convention; if you top-post while everyone else bottom-posts,
                        your articles are going to be harder to read that everyone else's.

                        Even if you assume that bottom-posting is better than top-posting, a
                        mixture of the two is going to be worse than either one used
                        consistently.

                        And, of course, the concern about scrolling past what's already been
                        said is addressed by trimming anything that's not relevant to your
                        response. If you expect your readers to scroll past it, why post it
                        in the first place?

                        --
                        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                        San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                        We must do something. This is something. Therefore, we must do this.

                        Comment

                        • CBFalconer

                          #27
                          Re: Array size limits

                          *** Evil top-posting fixed ***

                          grv575 wrote:[color=blue]
                          > Keith Thompson <kst-u@mib.org> wrote[color=green]
                          >> "Wei Li" <liwei_guard-pub@yahoo.com> writes:
                          >>[/color][/color]
                          ... snip ...[color=blue]
                          >[color=green][color=darkred]
                          >>> I don't know how ANSI C says. But the stacksize of a program
                          >>> in runtime is limited by Opterating System. So that C compiler
                          >>> always doesn't give out an compile time error.
                          >>>
                          >>> If you are on Linux, you can use "limit" command to show the
                          >>> limits and use "limit stacksize 1000000" to change them. I think
                          >>> your program will work OK[/color]
                          >>
                          >> Wei Li: Please don't top-post.
                          >>
                          >> Top-posting means writing your new material first, followed by the
                          >> quoted article to which you're responding. It makes it difficult
                          >> to follow the discussion, especially when (almost) everyone else
                          >> bottom-posts, as I'm doing there. (You should also trim anything
                          >> that's not relevant to your response, though in this case the
                          >> previous article was short enough that quoting the whole thing is
                          >> probably ok.)[/color]
                          >
                          > Please use google groups to read news. It syntax highlights
                          > everything so threads aren't difficult to follow either way. Btw,
                          > I prefer "topposting " since you don't have to scroll past what's
                          > already been said in the thread.[/color]

                          In comp.lang.c you are requested to bottom post (or interleave)
                          with proper snipping of irrelevant material. If you don't you may
                          well be plonked, which means that many people will never see any
                          of your posts. This tends to be non-productive.

                          Google groups is one of the slowest and awkwardest ways to read
                          news. Among other things many items never appear there, due to
                          foolish use of X-noarchive, and things that do appear have a delay
                          of several hours. On the other hand its archive is invaluable,
                          and it provides access for people without a newsreader (or behind
                          firewalls that prevent newserver access). This generally includes
                          library access, for example.[color=blue]
                          >
                          > I'm really surprised though that noone has pointed out so far that
                          > most compilers will have some kind of flag or directive to allow a
                          > larger stack size which is the most likely wall you're running in to
                          > (all this talk of standards and no real solutions).[/color]

                          Such compiler or system specific things are not portable, and are
                          thus off-topic here. Thus the proper reference is to a group
                          dealing with the specific system. There is not necessarily any
                          such thing as a stack.

                          --
                          A: Because it fouls the order in which people normally read text.
                          Q: Why is top-posting such a bad thing?
                          A: Top-posting.
                          Q: What is the most annoying thing on usenet and in e-mail?


                          Comment

                          • Martin Ambuhl

                            #28
                            Re: Array size limits

                            grv575 top-posted:
                            [color=blue]
                            > Please use google groups to read news.[/color]
                            [etc.]

                            Didn't you see the requests to Wei Li that he not top-post? Why do you
                            think you merit an exemption?

                            Comment

                            • grv575

                              #29
                              Re: Array size limits

                              Flash Gordon <spam@flash-gordon.me.uk> wrote in message news:<j47h02xjb n.ln2@brenda.fl ash-gordon.me.uk>.. .[color=blue]
                              > On 1 Sep 2004 07:59:26 -0700
                              > grv575@hotmail. com (grv575) wrote:
                              >[color=green]
                              > > Please use google groups to read news.[/color]
                              >
                              > Google is an on-line service that performs badly as a news reader. Many
                              > people read groups off-line for a number of good reasons, including
                              > dial-up connections where you pay per minute for being connected.[/color]

                              I've also used xnews quite a bit which also makes it irrelevant
                              whether the replies are top or bottom-posted. Top-posted text will be
                              visible first and it automatically skips quoted text (as an option).

                              The google comment could be change to 'use a decent threaded
                              newsreader' and it still wouldn't matter how someone chooses to reply
                              (assuming you thread the articles and read them as a group if you want
                              to get proper context).

                              Comment

                              • grv575

                                #30
                                Re: Array size limits

                                Martin Ambuhl <mambuhl@earthl ink.net> wrote in message news:<2pn2rqFn1 30qU2@uni-berlin.de>...[color=blue]
                                > grv575 top-posted:
                                >[color=green]
                                > > Please use google groups to read news.[/color]
                                > [etc.]
                                >
                                > Didn't you see the requests to Wei Li that he not top-post? Why do you
                                > think you merit an exemption?[/color]

                                Thanks for the dictatorial reply. If it's in the comp.lang.c faq then
                                that's fine, but what gives you or the previous poster any moderator
                                privledges?

                                Comment

                                Working...