Thread: Stack size

  1. #1
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735

    Stack size

    How do I change the size of the stack in c++? I would like to use larger arrays, and the stack overflows when I make them as large as I would like.

    Thanks,
    MadCow

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Use std::vector?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Thanks, that does the trick. Will I notice any difference performance wise?

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    You shouldn't, vectors shouldn't be much slower then an array, if not the same.
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > How do I change the size of the stack in c++?
    It depends on your OS and compiler.

    Besides, as Hunter2 suggested, take it as a hint that you should be looking for a better solution
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Thats interesting I though the stack was suposed to grow when all of it's space was used up?

  7. #7
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Quote Originally Posted by MadCow257
    Will I notice any difference performance wise?
    Quote Originally Posted by Bjarne Stroustrup
    vectors really are as fast as arrays.
    http://www.artima.com/intv/goldilocks.html

    Thats interesting I though the stack was suposed to grow when all of it's space was used up?
    Just out of curiosity, why would you think that?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Thats interesting I though the stack was suposed to grow when all of it's space was used up?
    That depends....

    Code:
    $ ulimit -a
    core file size        (blocks, -c) unlimited
    data seg size         (kbytes, -d) unlimited
    file size             (blocks, -f) unlimited
    open files                    (-n) 256
    pipe size          (512 bytes, -p) 8
    stack size            (kbytes, -s) 2043
    cpu time             (seconds, -t) unlimited
    max user processes            (-u) 63
    virtual memory        (kbytes, -v) 2097152
    Just a little under 2MB here.
    Of course I could set "unlimited", but it would still be limited by the very real limits of physical memory / swap space / address space.

    How you manipulate the same thing in say windows is another matter.

    You can't just put char x[1000000] inside a recursive function and sit back hoping that it'll work.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack Implementation and Exceptions
    By audinue in forum C Programming
    Replies: 4
    Last Post: 06-22-2008, 09:32 AM
  2. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  3. Need Help with Stack
    By trongsi in forum C++ Programming
    Replies: 9
    Last Post: 05-23-2006, 04:14 PM
  4. infix evaluation using stack
    By lewissi in forum C++ Programming
    Replies: 0
    Last Post: 11-03-2005, 02:56 AM
  5. Replies: 11
    Last Post: 03-25-2003, 05:13 PM