[net.unix-wizards] Realloc for Storage Compaction

elias@eosp1.UUCP (11/28/83)

=========================================

Does anyone know about (Sys.III-V) Sec.2-3 code which makes use of
the "storage compaction" feature(!?!) of "realloc"?

swatt@ittvax.UUCP (Alan S. Watt) (11/29/83)

In V7 and 4.1, "diff" uses these strange properties.  It also depends
on the fact that memory released via "free" is not modified until
the next "malloc" call.

The term "compacting reallocation" is misleading as memory is not
compacted in the usual sense of the word.  What does happen is that
the memory block is joined with adjacent blocks if they are free.

If you're about to try out alternate implementations of "malloc" and
friends, be aware that the following programs use "realloc" in some
form or another:

	/usr/src/cmd:
		cron.c
		nm.c

		.../cifplot:
			alloc.c
		.../csh:	(has its own copy of malloc.c)
			alloc.c
		.../diff:
			diff.c
		.../oldcsh:	(has its own copy of malloc.c)
			alloc.c
		.../oldcsh:	(has its own copy of malloc.c)
			malloc.c
		.../struct:
			0.parts.c

To my knowledge, only "diff" depends on realloc's strange properties.

My notes on 4.2 state that the "malloc" routines are identical to those
in 4.1, but that a new version was received and available for use.
The diff as distributed in 4.1 will break if you substitute a scheme
which alters memory on free operations.

	- Alan S. Watt

thomas@utah-gr.UUCP (Spencer W. Thomas) (11/30/83)

I think someone pointed out that "ed" also depends on the compaction scheme.
The version of the "Caltech malloc" distributed with 4.2 will "properly"
reallocate an already freed area.

=Spencer