[comp.lang.c] Microsoft C Problem

kemp@umn-cs.CS.UMN.EDU (Stuart R. Kemp) (11/11/89)

I have the the following problem using MSC 5.1:
(Yes, I have read the manual in an attempt to solve it!)

The problem is with malloc() and free(), using
large memory module.

Following is a contrived example to illustrate:

malloc() a large area, then free() it,
then malloc() a smaller area, and free() it,
then malloc() the large area again. 
The second time the large area is malloc()ed,
it will not be the same as the first area.
By carefully contriving an example, it would
be possible to have malloc() calls fail
when there *IS* enough memory available.

MSC gets blocks of memory from DOS, and controls
them internally, but it appears that it does
not do any merging of adjacent areas, nor
any intelligent selection of available areas.
The first large malloced area above is still available,
but only as a small area, and a larger area.
(Thus failure of malloc()'s mentioned above.)

In DOS, is is possible to control the allocation
strategy - I need something similar for MSC, or
a way to force MSC to release internal malloc()
areas back to DOS, and let DOS do any merging
of adjacent areas.

Is there something in the manual that I have missed?

Replies via email, please.

-Stuart Kemp
kemp@umn-cs.cs.umn.edu

Bob.Stout@p6.f506.n106.z1.fidonet.org (Bob Stout) (11/13/89)

  The MSC malloc/free problem is known and, as you note, can occasionally  
cause problems. Since Microsoft is only a month or so away from releasing MSC  
6.0, as I understand it, there are no plans to provide a fix for this in MSC  
5.x. The Microsoft Users Journal published some code a while back to defrag  
the heap as I recall, but I'm afraid I don't have any more details to offer.

bryan@quame.UUCP (Bryan A. Woodruff) (11/19/89)

In article <2646.255F599C@urchin.fidonet.org>, Bob.Stout@p6.f506.n106.z1.fidonet.org (Bob Stout) writes:
> 
>   The MSC malloc/free problem is known and, as you note, can occasionally  
> cause problems. Since Microsoft is only a month or so away from releasing MSC  
> 6.0, as I understand it, there are no plans to provide a fix for this in MSC  
> 5.x. The Microsoft Users Journal published some code a while back to defrag  
> the heap as I recall, but I'm afraid I don't have any more details to offer.

There are replacement functions for malloc/free - not Microsoft, but
they are public domain - I have used them for approx. 1.5 yrs with no
problems.  They are available on CompuServe --- for more info write:

Bryan Woodruff,
Quality America, Inc.
(uucp: ...!uunet!quame!bryan (bryan@quame.uu.NET))