need better MSC5.1 malloc() UPDATE

Cliff C Heyer cliffhanger at cup.portal.com
Mon Jun 4 01:36:17 AEST 1990


Re: MS-DOS MSC 5.1

This is a re-posting of my question posted last
week. To my surprise,  all my mail except one
came back from people saying "why would anyone 
need such a thing?" I guess I'm on the "outer 
bounds" of C programming....

What I am talking about is a "disk defragmentor"
for memory.

I would like to replace the MSC malloc() routines
with ones that do defragmentation. This is done 
by having malloc() maintain an internal table to
DEREFERENCE POINTERS. eg., when you do a
malloc(), malloc() returns an address that is not
a physical address but the address of a table
entry that contains the physical address. In this
way when your new malloc() can't find a big
enough contiguous chunk of memory and wants to 
return an "out of memory" condition, it can first 
do memcpy() to move the data to new physical 
addresses and update the table entries, thus 
compacting memory ("garbage collection" in my
previous posting.) 

Note that this is what a real OS does like UNIX, but
remember DOS is really just a program loader and
does no memory management for the program, so
with DOS you must do it yourself.

I'm AMAZED that there is not more attention to
this subject. Seeing how the DOS 640K limit is such a
problem, I would think that this problem would have
been tackled long ago.

This is EXACTLY what certain disk utilities
do to disks; DOS scatters clusters all over a disk
and the disk becomes fragmented, and the utility
"defragments" the disk.

Why do I need this?
I'm using a library (w/o source code) that with
heapwalk shows to have lousy memory management
(it was ported from a "real" OS that takes
care of these things) and after awhile malloc()
returns "Out of memory" when in fact there is
150KB free but broken up into 1KB chunks between
other "in use" data.

On DOS, it is the programmer's responsibility to take
care of memory because there is no OS to do it for
you! Windows 3.0 I understand does this.

Has anyone heard of such a library, and where it can
be bought?
Actually writing it myself appears no longer to be such
a chore!

Cliff



More information about the Comp.lang.c mailing list