Link to home
Start Free TrialLog in
Avatar of http29
http29

asked on

Don't know what happens, my application just hang

Hi Guru:

I am so frustrated with my application. I run it and it hangs, not giving me any message. Finally I found that my application might reach maximum size. I don't know, just guess. I use Borland C++. I have to change the code to reduce the size, then I can run it. But the problem is that I still need add more code. I don't understand, my code could be any large and should not be limited to some size. Please let me know what is real problem. Every time I add more codes, I got problem. I reduced and then can run it. Thanks.
Avatar of gj62
gj62

How much are you putting on the stack, vs on the heap?

Sounds like you are reaching a stack size issue.

Are you creating any large arrays, or medium size arrays with large structures?  If so, consider putting them on the heap with malloc().

Of course, this is all a SWAG since I've got no idea what your code looks like...

>> I have to change the code to reduce the size, then I can run it. But the problem is that I still need add more code.

Are you sure that the code you are removing isn't causing the program to freeze?

Exceter
are you forgetting to get out of a loop?  are you accessing null pointers?

Avatar of http29

ASKER

I am sure that the code I removed doesn't cause the programm to freeze because I just removed debug statements like cout << "..." << endl; Also I am not getting into the loop, should be not accessing null pointer, otherwise, I should get error message at least. Probably I am reaching a stack size. I do have large size array. What u mean by SWAG or by "putting them on the heap with malloc()". U mean using dynamic allocated memory instead of large array? Can I increase the stack size? How can I know how much I put on the stack, how much on the heap. Thanks.
SWAG = Scientific Wild A** Guess, or something to that approximation <grin>

To dynamically allocate memory (on heap instead of stack), instead of saying

type ReallyBigArray[arraysize]; or something like it, try

type *ReallyBigArray;

ReallyBigArray = (type *)malloc(sizeof(type) * arraysize);

Type can be anything - char, int, struct, etc.

I don't use Borland, but I think you can find (and even set) the stack size using the _stklen global variable.  I suggest, however, that a much better method would be to dynamically allocate the array (and any other large blocks of memory) on the heap.  As far as heap space - how much memory do you have... <grin>  

If this doesn't do it, what OS version and version of the compiler are you running under?  I probably can't help too much more, since manipulating stack size is done within each compiler, and as I said, I don't have Borland...
Check your Options-Compiler-Code Generation.
If the model there is tiny, small or compact, you have the chance to fix it by using large or huge model.

If the model is already large or huge,
don't use Borland C++ anymore and switch to DJGPP.
Avatar of http29

ASKER

Hi Kocil:

My model is huge model like you said. How easy to switch to DJGPP. I never used this one before and my project doesn't allow me more time to learn. We alreay released two versions. We got to keep going. So your help would be very much appreciated. Is DJGPP free download or need to buy? How much it is or the website? Thank you so much.
For DJGPP, go here:

http://www.delorie.com/djgpp/

DJGPP is free,
but i'm not sure about the license (GPL or else).
ASKER CERTIFIED SOLUTION
Avatar of Kocil
Kocil

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of http29

ASKER

Thank both Kocil and qj62. I understand that only one comment of your comments will be accepted as my answers. I feel very tough but would give to Kocil this time. But I really appreciate qj62.