10

I am using Visual Studio 13 to compile c codes for the first time. The codes run perfectly O.K. with 2d arays of size 64*64 (there are a few arrays in my programme) but if I increase the array size to 128*128 it does not run (but compile correctly). Instead it gives a message ".exe has stopped working". My machine has 4GB ram and the same programme run with 128*128 array if I run the codes from linux.

Let me provide some more details: I have run the same code from linux using Intel C Compiler (non-commercial version) in the same machine. But due to some problem I am now constrained to work from a Windows environment. I searched and have installed two c- compilers (1) Visual Studio 13 and (2) Borland C. Both work well with a small array. But the moment I increase array size Visual Studio give the message ".exe has stopped working". I compile the programme using 'cl' from "Developers Command Prompt VS 13".

I feel the problem is with stack size.

In the link detailed explanation (as provided below) I have seen a command "ulimit" used in linux environment to increase the stack size. I remember using it a few years ago.

I feel we are close to the solution, but my problem with Windows (and VS 2013) persists as I failed to execute dumpbin /headers executable_file or editbin /STACK:size. Actually I feel I do not know how to execute them. I tried to execute them from "Developer Command Prompt VS 13" as well as using Run (windows start bottom->search (run)->Run (prop up)). I request you kindly to provide more details if possible.

I searched and found this website and think here the solution can be found.

Please help. I want to run using Visual Studio 13 from Windows.

4
  • 1
    The problem exist, but it is impossible to find it based on your decription. You need to give us some code. Dec 23, 2013 at 13:35
  • 2
    whitout reading any further, I bet VS works!
    – A4L
    Dec 23, 2013 at 13:35
  • 2
    This is not because "Visual Studio is not working". 128*128 = 16384. If you have too little stack space, and you define an array of big enough structs, this can easily cause a stack overflow.
    – user529758
    Dec 23, 2013 at 13:36
  • I am sorry if my question has hurt any sentiment or regulation, directly or indirectly. No intension to break rules of this forum. Dec 24, 2013 at 2:33

3 Answers 3

15

It seems that the reason behind this is the stack overflow. The issue can be resolved by increasing the stack size.
In visual studio you can do this by using /STACK:reserve[,commit]. Read the MSDN article.


For more detailed explanation:

Under Windows platforms, the stack size information is contained in the executable files. It can be set during compilation in Visual studio C++.
Alternatively, Microsoft provides a program editbin.exe which can change the executable files directly. Here are more details:

Windows (during compilation):

  1. Select Project->Setting.
  2. Select Link page.
  3. Select Category to Output.
  4. Type your preferred stack size in Reserve: field under Stack allocations. eg, 32768 in decimal or 0x20000 in hexadecimal.

Windows (to modify the executable file):

There are two programs included in Microsoft Visual Studio, dumpbin.exe and editbin.exe. Run dumpbin /headers executable_file, and you can see the size of stack reserve information in optional header values. Run editbin /STACK:size to change the default stack size.

7
  • 2
    I think the user asking will need a more detailed explanation to fix his problem.
    – nvoigt
    Dec 23, 2013 at 13:36
  • @nvoigt; Yes. Keep eye on my answer. After few minutes it will be crystal clear.
    – haccks
    Dec 23, 2013 at 13:37
  • Stack overflow cannot be addressed by increasing heap size.
    – user3458
    Dec 23, 2013 at 13:38
  • 1
    Thank you. I have overcome the problem with the commands dumpbin and editbin. Ofcourse I required a little bit of more help from google search but finally your suggestion stands out. I can now run the codes with bigger array size. I also take this oppurtunity to thank the forum. Dec 24, 2013 at 5:28
  • What is the unit used in /STACK? Byte? KB? I find it surprising that this is not mentioned in official doc.
    – Yufan Lou
    Oct 13, 2017 at 1:59
1

Visual Studio does not work?

Although I don't regard VS as a valid development tool, I highly doubt that it would cause your problem.

128 * 128 is 16384. If you have too little stack space (on Windows, it's 1MB by default if I'm not mistaken), and you define an array of e. g. big enough structs (sized 64 bytes, more precisely), then this can easily cause a stack overflow, since automatic arrays are typically (although not necessarily) allocated on the stack.

0
1

It sounds like you're trying to declare large arrays on the stack. Stack memory is typically limited; it sounds like you're overflowing it.

You can fix this by giving your array static duration

static BigStruct arr[128][128];

or by dynamically allocating memory for it

BigStruct (*arr)[128] = malloc(sizeof(*arr) * 128);
// use arr
free(arr);
3
  • I do not want to use "malloc" although the entire programme can be readjusted using "malloc". Why? Let us leave it for another day. But I am interested to know about "static BigStruct arr[128][128];". I declare array simply as "double arr[128][128];" as I require double precision in my calculation. Do you recommend me to use something like "static BigStruct double arr[128][128];"? Will it help. Please let me know. Dec 24, 2013 at 2:57
  • BigStruct isn't a C keyword. Your question didn't say what you had an array of so it was a placeholder for your array type. If you want an array of doubles with static duration, use static double arr[128]128];
    – simonc
    Dec 24, 2013 at 8:02
  • I write ordinary simple programme to simulate classical fluid flow problems, like flow past circular cylinder etc. The arrays are used to store different flow variables, velocity etc. As I have already stated the entire programme can be adjusted to use malloc (linked list), which will be memory economical but at the same time for simple problem will introduce lot many things which I want to avoid. I would now try with 'static double arr[128][128];' Let me see how it performs. Thanks for the suggestion. Dec 24, 2013 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.