June 22nd, 2003, 11:23 AM
[C] Lost in Memory Space (possibly malloc)
I have been trying for some time now to convert a C++ program that loads 3DS files to C. I have had partial success. Some models load ok but with annoying regularity some cause an unhandled exception error.
I have tracked the offending line to :
After several hundred iterations it fails at the malloc ie prints the first message but not the second. The debug window reports the following:
chunk *current_chunk; //In header. Chunk is just a 16 byte struct.
printf("Is Malloc the cause: ");
current_chunk = (chunk*)malloc(sizeof(chunk));
HEAP[Neo Blitz.exe]: Heap block at 003C48C0 modified at 003C4A7C past requested size of 1b4
Unhandled exception at 0x77f767cd in Neo Blitz.exe: User breakpoint.
I did have a check to see what malloc returns but the problem is that it isn't returning all.
I am using VS .Net (vc++ 7)
Any advice would be appreciated.
June 25th, 2003, 02:03 AM
Fails after hundreds of times? My first thought was that you ran out of memory. Are you freeing the memory (free())?? Malloc takes memory from the program's heap...which is just a stack structure specifically for the program. You can either increase the heap size...through compiler settings...or check out farmalloc()....and why are you converting from C++ to C? Reinventing the wheel?
June 25th, 2003, 02:47 AM
I cut my code for the post but the original code a test to see if malloc returned NULL (is returned when insufficient memory, according to the specs) so I don't think it was memory, but then again I am still learning the ins and outs of C.
The quick reason for C is that this code was to be transported to an environment that does not support C++ (linux for PS2).
I have found a workaround for the problem -only took about 8 hours : ( - but thanks for the advice.