Array overflow in Windows

Discussion in 'C' started by IanLiu, Feb 9, 2007.

  1. IanLiu

    IanLiu New Member

    Joined:
    Feb 9, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hello there.
    I am new to this forum and it seems very good.

    I was programming in C with Windows and I need a 2d-array with 800x800 entries.
    It doesn't seem very big, but... when I run the program, it fails.

    Code:
    int main() {
    	int M[800][800];
    	return 0;
    }
    In Linux all works well. Any tips?

    Regards,
    Ian Liu.
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Your question does not lead to an appropriate response. Information is key. How does it fail? What messages do you get? Does the system just crash? Which Windows OS are you using? The size is not unduly large, but you may have an old underpowered (in terms of memory resources) system.
     
  3. IanLiu

    IanLiu New Member

    Joined:
    Feb 9, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Oh yes... sorry, I was too "hungry" for a quick solution. Well,
    my PC is a:
    Pentium 4, 1.7 GHz
    1GB RAM

    I use Windows XP with no SP versions installed (but I think it happened with SPed windows too).

    The error message is that pop-up window that appears when a program crashes and has to be closed. You have the option to report the error, or just finish it. It is something like this image:
    [​IMG]

    Sorry again for the bad post!
    Think this is usefull.

    Regards,
    Ian Liu.
     
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    I had no problem with your program with VC++ 6.0. It generated a stack overflow, however, with VC++ 2005. I checked the stack commit and stack reserve sizes in the project properties and found that both were set to 0. I set them to 1000 and fixed the problem. In 2005 you will find this at Project/(project name) Properties/Configuration Properties/Linker/System.
     
  5. IanLiu

    IanLiu New Member

    Joined:
    Feb 9, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Oh yes, I forgot to say that I am not using VC++, I am using GCC, from DevCpp.

    I will try to install CygWin and see if the problem persist :)
    I don't like to use proprietary applications, but I wanted the program to work on windows.

    Any tips on GCC?

    Well, enough questions.
    Good night to you!

    Ian Liu.
     
  6. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Another reason you should provide all the information you can when asking a question. Let me recommend Smart Questions.

    With Dev-Cpp the program does indeed crash at 800 x 800. Dev-Cpp (gcc family, perhaps I should say) doesn't seem to offer an option for controlling the amount of stack allowed. Perhaps you should try allocating on the heap, as virtual memory in decent OSes tends to make the amount available unlimited (well, limited by disk size).

    You're certainly entitled to prefer non-proprietary tools, but sometimes you just get fewer amenities and capabilities. I never could convince ex-wife #2 that a high-heeled shoe wasn't really the best hammer.
     
  7. IanLiu

    IanLiu New Member

    Joined:
    Feb 9, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Thank you very much DaWei.
    I think I've learned much more than I expected.

    I just don't agree with the hammer part ;)

    Best wishes,
    Ian Liu.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice