PRB: Memory Allocation Error When Using halloc() or malloc()

ID Number: Q37201

5.00 5.10 6.00 6.00a 6.00ax 7.00

MS-DOS

Summary:

SYMPTOMS

In Microsoft C versions 5.1, 6.0, 6.0a, 6.0ax, and C/C++ version 7.0,

while running a program you have created that uses halloc() or

malloc(), MS-DOS may print the following message:

Memory Allocation Error

Cannot Load COMMAND.COM.

You are able to allocate, use, write, read, and free memory, but

when your program finishes, you receive the error.

CAUSE

Your program is probably writing outside of a memory block you

allocated using halloc() or malloc(). MS-DOS maintains information

about memory usage in blocks immediately preceding the memory given

by halloc(). There is also a header following each entry in the

heap. The error is usually a result of overwriting these

information blocks and headers. The solution is to find out where

the program is overwriting memory and correct it.

RESOLUTION

You can determine which part(s) of the program overwrites the

memory by using CodeView to set a tracepoint or a breakpoint on the

memory in question. If you don't have enough memory to run

CodeView, you can narrow down the problem by using a pointer to

check those bytes at selected points in your program.

Additional reference words: 5.10 6.00 6.00a 6.00ax 7.00