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. It crashes !

It crashes !

Scheduled Pinned Locked Moved C / C++ / MFC
9 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.
  • V Offline
    V Offline
    vikramlinux
    wrote on last edited by
    #1

    void function(void) { int i[1000000]; } int main(int argc, char* argv[]) { function(); return 0; }

    A N R I D 5 Replies Last reply
    0
    • V vikramlinux

      void function(void) { int i[1000000]; } int main(int argc, char* argv[]) { function(); return 0; }

      A Offline
      A Offline
      Anand for every one
      wrote on last edited by
      #2

      your RAM memory might not contain that much of memmory. or you try with calloc or malloc

      V 1 Reply Last reply
      0
      • A Anand for every one

        your RAM memory might not contain that much of memmory. or you try with calloc or malloc

        V Offline
        V Offline
        vikramlinux
        wrote on last edited by
        #3

        Hey buddy my RAM is 1 GB.

        U 1 Reply Last reply
        0
        • V vikramlinux

          Hey buddy my RAM is 1 GB.

          U Offline
          U Offline
          User 307386
          wrote on last edited by
          #4

          Doesn't matter, how big your memory is. Your data is allocated on stack, and there is a limit for stack size. I'm not sure about default stack (1Mb?), you can check docs for it, you can also adjust its size in compiler settings. But allocation of big memory blocks on stack is very bad practice. Igor Green http://www.grigsoft.com/ Compare It! + Synchronize It! - files and folders comparison never was easier!

          A 1 Reply Last reply
          0
          • V vikramlinux

            void function(void) { int i[1000000]; } int main(int argc, char* argv[]) { function(); return 0; }

            N Offline
            N Offline
            namaskaaram
            wrote on last edited by
            #5

            well i guess itz becoz maybe getting an array if 1000000 integetez basically impliez u need 400000 bytez of location(one block) together (which may not be present/possible!!!!!:~ ).....i dunno.....:~.....if thiz iz a consoole tye that u have done,then ,what kind memory model have u chosen(maybe that could be the reason.....please check that up......i dont see any other reason):~ "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13

            1 Reply Last reply
            0
            • V vikramlinux

              void function(void) { int i[1000000]; } int main(int argc, char* argv[]) { function(); return 0; }

              R Offline
              R Offline
              Ryan Binns
              wrote on last edited by
              #6

              You're allocating 4MB of memory on the stack. Generally, your stack size is a lot less than that. If you need to allocate this amount of memory, allocate it on the heap with a "new" call.

              Ryan

              "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

              1 Reply Last reply
              0
              • U User 307386

                Doesn't matter, how big your memory is. Your data is allocated on stack, and there is a limit for stack size. I'm not sure about default stack (1Mb?), you can check docs for it, you can also adjust its size in compiler settings. But allocation of big memory blocks on stack is very bad practice. Igor Green http://www.grigsoft.com/ Compare It! + Synchronize It! - files and folders comparison never was easier!

                A Offline
                A Offline
                Anand for every one
                wrote on last edited by
                #7

                I also think Igor Green is correct. And use calloc or new or someother

                1 Reply Last reply
                0
                • V vikramlinux

                  void function(void) { int i[1000000]; } int main(int argc, char* argv[]) { function(); return 0; }

                  I Offline
                  I Offline
                  ionzarate
                  wrote on last edited by
                  #8

                  It´s because you are overflowing the stack!! The stack is the part of memory used for keeping function arguments and return adresses when calling a function, but it is also where the LOCAL VARIABLES are kept. By default the size of the stack is 1 MB, and you need at least 4 MB of stack for your "int i[1000000]" array. (4 bytes each int, 1000000 times). You need to make your stack greater. In VisualC++ 6.0: Proyect->Settings->Link->Output->Stack allocations In the "Reserve" text box, try greater values. Bye! :wtf:

                  1 Reply Last reply
                  0
                  • V vikramlinux

                    void function(void) { int i[1000000]; } int main(int argc, char* argv[]) { function(); return 0; }

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    Variable i is a stack-based variable. The default size of a program's stack is 1MB. You have obviously exceeded that amount.


                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                    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