1833184 Members
3188 Online
110051 Solutions
New Discussion

Memory Exhausted

 
Mustafa Motiwala
Occasional Advisor

Memory Exhausted

Hello folks,
There is this recurring problem with a small utility that i have written. Its basically a conversion utility that parses information from a propriety binary format to XML. The problem is that with small files the utlity works fine. But with a binary file of around 7 Megs, the utility does a core dump with an error:
Memory exhausted.
What could be the problem and posibble cure? I have
RAM=512 Megs
swap=1024
OS=HP-UX 11.00
5 REPLIES 5
harry d brown jr
Honored Contributor

Re: Memory Exhausted


You need to look at your kernel parameters, and of course your program to make sure you aren't consuming all of the available memory.

Post the kernel parameters here and we will take a look at them.

live free or die
harry
Live Free or Die
A. Clay Stephenson
Acclaimed Contributor

Re: Memory Exhausted

I am going to take a wild guess but the default stack size is 8MB and that could be your problem. You don;t mention what language that this program was written in but if you are using a lot of local variables (especially with recusrion), you could very easily exhaust stack space. You could increase maxssiz but the better answer is to look at your code and see if you can't dynamically allocate memory (and free it when finished).
If it ain't broke, I can fix that.
Mustafa Motiwala
Occasional Advisor

Re: Memory Exhausted

Hi,
Thanx for the tips, the code is in C. I am looking into mending the code, but its a bit difficult, coz to allocate dynamic memory i dont know before hand exactly how much i will need.any suggestions?
Thanx.
P.S. Sorry for the late feedback, was out of reach due to weekend.
Adam J Markiewicz
Trusted Contributor

Re: Memory Exhausted

I wouldn't dare to argue with olympian, but I think that stack problems would have more stack-related error.

Check this:

int fun( void )
{
char arr[ 1 << 24 ]; // eat stack
return fun();
}

int main( void )
{
return fun();
}

aCC, run:

Pid 23574 received a SIGSEGV for stack growth failure.
Possible causes: insufficient memory or swap space,
or stack size exceeded maxssiz.
Segmentation fault (core dumped)


I think that exhausting heap is the problem here. Check maxdsiz, and the most important: Check very carefully if you're freeing absolutelly everything allocated by you earlier.

Good luck

Adam
I do everything perfectly, except from my mistakes
A. Clay Stephenson
Acclaimed Contributor

Re: Memory Exhausted

'Memory exhausted' is not an OS defined error message but is almost certainly an application defined error message. You really need to know the value of errno when you crash or better yet compile with -g and no optimization and then let your program die. You then use a debugger to do a stack trace to zero in on the line of code that is causing your program to crash.

Dynamic memory does not require that you know exactly how much memory you need but only how much ADDITIONAL memory you need at this moment. For example, using the sizeof() pseudofunction, you might find that you need 80 bytes for a struct, you then call malloc(), calloc(), or realloc() with the value you obtained from sizeof().
If it ain't broke, I can fix that.