PDA

View Full Version : Malloc/new never returns


OdeeanRDeathshead
30th March 2007, 02:02 PM
I have a problem.

I make use of malloc or new in many places to store data in. I normally have no problem but there seems to be a limit on how much I can use it. I always free/delete as soon as I no longer need the memory and always check for 0 returned. I have mechanisms in place in case of 0 but when malloc actually fails it dose not return. Malloc just never returns and hence crashes my program. What could be the cause of this?

+The actual memory I am requesting is ~2-20k, the available memory is 20-30mb.

I am considering creating a heap, using it to allocate blocks from and destroying it to clean the memory. This is a time consuming change, dose anybody have some experience with this problem?

The annoying part is that the code works 100% on old devices and fails on new ones. I never thought i would be rewriting this code.

OdeeanRDeathshead
30th March 2007, 03:45 PM
The heap way did work. The problem is that on ce, to create a heap you have to set aside the size first. Also there are still some problems I am having with memory that I pass out of a dll and then pass back in to free. Still its better than crashing! I may solve the freeing of individual pointers by just replacing it with a periodic call to HeapDestroy to clear them all out, something else that can't be done with malloc.