#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    2
    Rep Power
    0

    [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 :
    Code:
    chunk *current_chunk; //In header.  Chunk is just a 16 byte struct.
    printf("Is Malloc the cause:  ");
    current_chunk = (chunk*)malloc(sizeof(chunk));
    printf("NOPE\n");
    After several hundred iterations it fails at the malloc ie prints the first message but not the second. The debug window reports the following:
    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.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    3
    Rep Power
    0
    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?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    2
    Rep Power
    0
    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.

IMN logo majestic logo threadwatch logo seochat tools logo