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. increase stack size in VC++ 2002

increase stack size in VC++ 2002

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structureshelpquestion
13 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.
  • S Offline
    S Offline
    sleze
    wrote on last edited by
    #1

    I am running a program that manipulates images using int arrays as a substitute for the images. Well I can't create another one because it causes a stack overflow error. If I make it 200x100, I have enough space. If I make it 200x200, it goes over. I have read that you can increase the stack size using /F 1024000 but that doesn't seem to work. Any ideas? Right now I have converted all the arrays to short instead of int as a workaround but that seems silly on a machine with 512MB of RAM.

    C S 2 Replies Last reply
    0
    • S sleze

      I am running a program that manipulates images using int arrays as a substitute for the images. Well I can't create another one because it causes a stack overflow error. If I make it 200x100, I have enough space. If I make it 200x200, it goes over. I have read that you can increase the stack size using /F 1024000 but that doesn't seem to work. Any ideas? Right now I have converted all the arrays to short instead of int as a workaround but that seems silly on a machine with 512MB of RAM.

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      don't allocate them on the stack. that's why jesus invented malloc and new. Cleek | Image Toolkits | Thumbnail maker

      S C 2 Replies Last reply
      0
      • C Chris Losinger

        don't allocate them on the stack. that's why jesus invented malloc and new. Cleek | Image Toolkits | Thumbnail maker

        S Offline
        S Offline
        sleze
        wrote on last edited by
        #3

        I am not sure I am doing this right. This is what my code looks like now: short temparray[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH]; I am trying to use new short * temparray = new short[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH]; but that gets an error message saying that it can't convert type short (*) to short [][320] I can't find any examples of malloc being used with arrays.

        J W 2 Replies Last reply
        0
        • S sleze

          I am not sure I am doing this right. This is what my code looks like now: short temparray[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH]; I am trying to use new short * temparray = new short[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH]; but that gets an error message saying that it can't convert type short (*) to short [][320] I can't find any examples of malloc being used with arrays.

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          short* temparray = new short[PICTUREARRAYHEIGHT * PICTUREARRAYWIDTH];
          temparray[y * PICTUREARRAYWIDTH + x] = value;

          is a simple solution. No need to allocate an array of arrays, which you'd have to do if you had wanted to access the pixels in "2d"-fashion.

          1 Reply Last reply
          0
          • S sleze

            I am running a program that manipulates images using int arrays as a substitute for the images. Well I can't create another one because it causes a stack overflow error. If I make it 200x100, I have enough space. If I make it 200x200, it goes over. I have read that you can increase the stack size using /F 1024000 but that doesn't seem to work. Any ideas? Right now I have converted all the arrays to short instead of int as a workaround but that seems silly on a machine with 512MB of RAM.

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            Forget using malloc and free or even new and delete. Do it using a std::vector. e.g. // So we can access "std::vector". #include <vector>   // We want a vector of ints. typedef std::vector<int> t_IntVec;   // Now use the vector in a similar way you'd use the dynamically allocated array. t_IntVec ints(200*200); ints[1*200 + 5] = 1; Steve

            S 1 Reply Last reply
            0
            • S Stephen Hewitt

              Forget using malloc and free or even new and delete. Do it using a std::vector. e.g. // So we can access "std::vector". #include <vector>   // We want a vector of ints. typedef std::vector<int> t_IntVec;   // Now use the vector in a similar way you'd use the dynamically allocated array. t_IntVec ints(200*200); ints[1*200 + 5] = 1; Steve

              S Offline
              S Offline
              sleze
              wrote on last edited by
              #6

              I'll try that tomorrow when I get back into work. Isn't there ANY way to just increase the size of the stack so I can use plain old 2-d arrays?

              S 1 Reply Last reply
              0
              • S sleze

                I'll try that tomorrow when I get back into work. Isn't there ANY way to just increase the size of the stack so I can use plain old 2-d arrays?

                S Offline
                S Offline
                Stephen Hewitt
                wrote on last edited by
                #7

                The /STACK linker switch. See here[^]. Steve

                S 1 Reply Last reply
                0
                • C Chris Losinger

                  don't allocate them on the stack. that's why jesus invented malloc and new. Cleek | Image Toolkits | Thumbnail maker

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

                  :) Nice Chris, i needed a good chuckle. ...cmk Save the whales - collect the whole set

                  1 Reply Last reply
                  0
                  • S sleze

                    I am not sure I am doing this right. This is what my code looks like now: short temparray[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH]; I am trying to use new short * temparray = new short[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH]; but that gets an error message saying that it can't convert type short (*) to short [][320] I can't find any examples of malloc being used with arrays.

                    W Offline
                    W Offline
                    Waldermort
                    wrote on last edited by
                    #9

                    sleze wrote:

                    short * temparray = new short[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH];

                    You can't create 2D arrays like this using new. Try this instead

                    short **temparray = new short*[PICTUREARRAYHEIGHT];
                    for (int i=0;i<PICTUREARRAYHEIGHT;i++)
                    temparray[i] = new short[PICTUREARRAYWIDTH];

                    You would also have to delete using a similar method to prevent leaks.

                    1 Reply Last reply
                    0
                    • S Stephen Hewitt

                      The /STACK linker switch. See here[^]. Steve

                      S Offline
                      S Offline
                      sleze
                      wrote on last edited by
                      #10

                      That solved the normal stack overflow error. But now I have a new one. When I try to move the window once image processing is going on, the program crashes with a stack overflow error. Increasing the stack to 10MB doesn't seem to fix it. Any ideas?

                      S 1 Reply Last reply
                      0
                      • S sleze

                        That solved the normal stack overflow error. But now I have a new one. When I try to move the window once image processing is going on, the program crashes with a stack overflow error. Increasing the stack to 10MB doesn't seem to fix it. Any ideas?

                        S Offline
                        S Offline
                        Stephen Hewitt
                        wrote on last edited by
                        #11

                        I was reluctant to tell you about the /STACK switch because I had doubts that it would fix your problem - most times "the quick fix" causes more problems then it solves. 200x200 integers is just 200x200x4=[EDIT]160KB[/EDIT]. It seems unlikely that the size of the array was actually the cause of the problem. I suspect the problem is that you're recursing too deeply. Can you send a stack trace when you get the crash? Steve -- modified at 8:55 Saturday 22nd April, 2006

                        N 1 Reply Last reply
                        0
                        • S Stephen Hewitt

                          I was reluctant to tell you about the /STACK switch because I had doubts that it would fix your problem - most times "the quick fix" causes more problems then it solves. 200x200 integers is just 200x200x4=[EDIT]160KB[/EDIT]. It seems unlikely that the size of the array was actually the cause of the problem. I suspect the problem is that you're recursing too deeply. Can you send a stack trace when you get the crash? Steve -- modified at 8:55 Saturday 22nd April, 2006

                          N Offline
                          N Offline
                          Nick_Kisialiou
                          wrote on last edited by
                          #12

                          Isn't 200x200x4 = 160K?

                          S 1 Reply Last reply
                          0
                          • N Nick_Kisialiou

                            Isn't 200x200x4 = 160K?

                            S Offline
                            S Offline
                            Stephen Hewitt
                            wrote on last edited by
                            #13

                            Oops - you're right. That is a lot to have on the stack. Steve

                            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