need better MSC5.1 malloc() UPDATE

Inst.f.Techn.Informatik inst182 at tuvie
Thu Jun 7 03:00:43 AEST 1990


cliffhanger at cup.portal.com (Cliff C Heyer) writes:
>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.
> 
> ...
>
>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.

I don't think such an indirect malloc library would be of 
much use in your case.
If a library routine calls malloc () it expects to get 
a pointer to the allocated memory block, not a pointer to a pointer
to this block. It would happily thrash your table.
If you had the source, however you could change all *s to **s, but
then you could change the memory management of this library, too.

>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.

Most "Real OSes" do garbage collection with a MMU (how else
could the pointers remain unchanged), which the 8086 just doesn't
have. It would be possible in protected mode on 80[234]86 systems,
by using a segment per pointer, but switching segments is SLOW
(I have been told, I just sold my XT, and bought a 386, and 
haven't done much experimenting yet). So even on a 80386 UNIX
system you wouldn't have any garbage collection, although the unused
blocks would probably only accumulate in the swap space, not in 
main memory.

>Cliff

|    _	| Peter J. Holzer			| Think of it	|
| |_|_)	| Technische Universitaet Wien		| as evolution	|
| | |	| hp at honey.tuwien.ac.at			| in action!	|
| __/  	| ...!uunet!mcsun!tuvie!asupa!honey!hp	|     Tony Rand	|



More information about the Comp.lang.c mailing list