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 / C++ / MFC
  4. Stack overflow

Stack overflow

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelp
14 Posts 7 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.
  • L Lost User

    I have trouble with declaring my array size so as to avoid the stack overflow error: _variant_t raw_data[10000][100] _variant_t results[10000][100] i read somewhere about dynamic sizing, i tried this but it didnt work _variant_t *raw_data = new _variant_t [10000][100] any help would be very much appreciated..

    L Offline
    L Offline
    Luc Pattyn
    wrote on last edited by
    #3

    Hi, IIRC stack space is limited to 1MB, so you can't create a stack-based array holding 1M elements. You could dynamically allocate it though, using malloc() or new. :)

    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


    Getting an article published on CodeProject should be easier and faster for Bronze and Silver authors.


    T 1 Reply Last reply
    0
    • L Luc Pattyn

      Hi, IIRC stack space is limited to 1MB, so you can't create a stack-based array holding 1M elements. You could dynamically allocate it though, using malloc() or new. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      Getting an article published on CodeProject should be easier and faster for Bronze and Silver authors.


      T Offline
      T Offline
      Tim Craig
      wrote on last edited by
      #4

      I'm going by memory, too, but I think the default stack is 1 Meg but you can set it to be a different size as part of the build. I've never personally done it though. :suss:

      You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

      L C 3 Replies Last reply
      0
      • T Tim Craig

        I'm going by memory, too, but I think the default stack is 1 Meg but you can set it to be a different size as part of the build. I've never personally done it though. :suss:

        You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #5

        Tim Craig wrote:

        but you can set it to be a different size as part of the build.

        yeah, that is very plausible, however I never have done so for a Windows app. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        Getting an article published on CodeProject should be easier and faster for Bronze and Silver authors.


        1 Reply Last reply
        0
        • T Tim Craig

          I'm going by memory, too, but I think the default stack is 1 Meg but you can set it to be a different size as part of the build. I've never personally done it though. :suss:

          You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #6

          Tim Craig wrote:

          but you can set it to be a different size as part of the build.

          yeah, that is very plausible; it is common practice for embedded systems, however I never have done so for a Windows app. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          Getting an article published on CodeProject should be easier and faster for Bronze and Silver authors.


          1 Reply Last reply
          0
          • L Lost User

            I have trouble with declaring my array size so as to avoid the stack overflow error: _variant_t raw_data[10000][100] _variant_t results[10000][100] i read somewhere about dynamic sizing, i tried this but it didnt work _variant_t *raw_data = new _variant_t [10000][100] any help would be very much appreciated..

            A Offline
            A Offline
            Adam Roderick J
            wrote on last edited by
            #7

            Try with malloc, that can used to represent multidimensional array.

            int **nArray;
            int nRows = 10000;
            int nColumn = 100;
            nArray = (int**)malloc(nRows * sizeof(int *));
            ZeroMemory( nArray, 0 );
            if( 0 == nArray )
            {
            return 0;
            }
            for(int i = 0; i < nRows; i++)
            {
            nArray[i] = (int*)malloc( nColumn * sizeof(int));
            if( 0 == nArray[i] )
            {
            return 0;
            }
            }

            Величие не Бога может быть недооценена.

            1 Reply Last reply
            0
            • T Tim Craig

              I'm going by memory, too, but I think the default stack is 1 Meg but you can set it to be a different size as part of the build. I've never personally done it though. :suss:

              You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #8

              You remember well [^]. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              T 1 Reply Last reply
              0
              • C CPallini

                You remember well [^]. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                T Offline
                T Offline
                Tim Craig
                wrote on last edited by
                #9

                I remember a poem in Mad Magazine in the late 50's that went "I remember, I remember...", but I can't remember what they remembered. :sigh:

                You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

                C 1 Reply Last reply
                0
                • T Tim Craig

                  I remember a poem in Mad Magazine in the late 50's that went "I remember, I remember...", but I can't remember what they remembered. :sigh:

                  You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #10

                  You are lucky. On the other hand: "I don't remember, I don't recall I got no memory of anything at all" :-D

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  1 Reply Last reply
                  0
                  • L Lost User

                    I have trouble with declaring my array size so as to avoid the stack overflow error: _variant_t raw_data[10000][100] _variant_t results[10000][100] i read somewhere about dynamic sizing, i tried this but it didnt work _variant_t *raw_data = new _variant_t [10000][100] any help would be very much appreciated..

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #11

                    so i tried this but keep getting errors on _variant_t *p line: **************************************************** initialize array vector<_variant_t> d(10000); //_variant_t** 2d = new _(variant_t*)[10000]; for(long k = 0; k < d.size(); ++k) { d[k] = new _variant_t(); *********************************************************** delete array for(k = 0; k < d.size(); ++k) { _variant_t* p = d[k]; (error = cannot convert from 'class _variant_t' to 'class _variant_t *') delete [] p; }

                    J 1 Reply Last reply
                    0
                    • L Lost User

                      so i tried this but keep getting errors on _variant_t *p line: **************************************************** initialize array vector<_variant_t> d(10000); //_variant_t** 2d = new _(variant_t*)[10000]; for(long k = 0; k < d.size(); ++k) { d[k] = new _variant_t(); *********************************************************** delete array for(k = 0; k < d.size(); ++k) { _variant_t* p = d[k]; (error = cannot convert from 'class _variant_t' to 'class _variant_t *') delete [] p; }

                      J Offline
                      J Offline
                      jagadish bharath
                      wrote on last edited by
                      #12

                      hi, use vector<_variant_t*> d(10000); instead of vector<_variant_t> d(10000);

                      L 1 Reply Last reply
                      0
                      • J jagadish bharath

                        hi, use vector<_variant_t*> d(10000); instead of vector<_variant_t> d(10000);

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #13

                        Thanks it worked but even after compiling the code, i still get stack overflow: this is how am declaring my array: static const int N = 9990; static const int N2 = 96; vector<_variant_t*> d(N); for(long k = 0; k < d.size(); ++k) { d[k] = new _variant_t(); } _variant_t raw_data[N][N2]; _variant_t filter_results[N2]; _variant_t results2[N][N2] _variant_t Filtered_Average[N];

                        J 1 Reply Last reply
                        0
                        • L Lost User

                          Thanks it worked but even after compiling the code, i still get stack overflow: this is how am declaring my array: static const int N = 9990; static const int N2 = 96; vector<_variant_t*> d(N); for(long k = 0; k < d.size(); ++k) { d[k] = new _variant_t(); } _variant_t raw_data[N][N2]; _variant_t filter_results[N2]; _variant_t results2[N][N2] _variant_t Filtered_Average[N];

                          J Offline
                          J Offline
                          jagadish bharath
                          wrote on last edited by
                          #14

                          you are trying to create a multidimenional array on stack. normally stack has a limitation of 2MB but heap can go upto around 100 MB. create all the variables in heap and importantly delete it after using. this is a classic multi dimension c++ mem allocation. sample : _variant_t **raw_data[N]; for(int nOut = 0;nOut < N;nOut++) { raw_data[nOut] = new _variant_t*[N2]; for(int nIn = 0;nIn < N2;nIn++) { raw_data[nOut][nIn]= new _variant_t(nIn);// sample initialization } } // delete this is important for(int nOut = 0;nOut < N;nOut++) { for(int nIn = 0;nIn < N2;nIn++) { delete raw_data[nOut][nIn]; } delete raw_data[nOut] ; }

                          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