Hello!

I have written a nested for loop with an inner loop of 86400 iterations and the outer loop 365. It compiles and everything but only gives me 97 of the 365 results. This is the error message:

aqua(855) malloc: *** mmap(size=268435456) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
terminate called after throwing an instance of 'std::bad_alloc'
  what():  St9bad_alloc

When I googled it people said it was because the computer didn't have enough memory. But I tried running it on a school computer and had exactly the same problem, with 97 results again. Does anyone know if there is any way of getting around this?

Thank you!

So, your program is trying to make 31,536,000 memory allocations (86400 X 365) ???

how much memory is being allocated at one time? Is any of the memory ever released?

That is huge!! Try freeing up memory from before? Any memory you allocated before, Use it and then free it! Cuz if it isn't free, sooner or later your gunna get what u have above...

Try allocating a smaller amount of space. Do you really need that much?

Well, yes, I see your point.

No i never release any of the memory. The 86400 is the amount of seconds in a day. The next day should start on the value for the previous day, so I'm not sure how I could release this memory? Or could I release the memory after a delay of say 2 days? How do I go about releasing memory?

Thanks very much.

I tried writing

free (my_vector[i-1]);

but it's not into that..

Hang on.. A vector frees its memory itself, no? So is it just that I can't make 86400 iterations in one piece of code? Should I do half in one file and half in another? Thanks for any help.

We have no idea what you are trying to do with all that memory so we can't really help you very much. You're going to have to post some valid code and explain what the program is doing if you really expect any better help than what you've already received. Afterall, we can't see your monitor or read your mind. But be careful not to post anything you will later regret because DaniWeb will not delete it once posted.

This seems to be on a Unix/Linux system, correct? Chances are you have exceeded the amount of memory available to you as specified by your ulimit environment settings. This is to keep individual processes from eating up all system RAM. On my system, since I am the sole user and administrator, I set my limits to "unlimited" because I have some applications that of necessity use a lot of RAM. However, this is very unsafe, especially if you have a buggy program that gets into a "runaway" state while allocating memory. I have one application that occasionally does this, and I have to catch/kill it when it starts to hit the swapper.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.