3 * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
5 * This product is part of the Amsterdam Compiler Kit.
7 * Permission to use, sell, duplicate or disclose this software must be
8 * obtained in writing. Requests for such permissions may be sent to
10 * Dr. Andrew S. Tanenbaum
11 * Wiskundig Seminarium
19 /* Author: J.W. Stevenson */
23 #define assert() /* nothing */
26 * use circular list of free blocks from low to high addresses
27 * _highp points to free block with highest address
34 extern struct adm
*_lastp
;
35 extern struct adm
*_highp
;
38 static int merge(p1
,p2
) struct adm
*p1
,*p2
; {
41 p
= (struct adm
*)((char *)p1
+ p1
->size
);
51 _dis(n
,pp
) int n
; struct adm
**pp
; {
55 * NOTE: dispose only objects whose size is a multiple of sizeof(*pp).
56 * this is always true for objects allocated by _new()
58 n
= ((n
+sizeof(*p1
)-1) / sizeof(*p1
)) * sizeof(*p1
);
61 if ((p1
= *pp
) == (struct adm
*) 0)
64 if ((p2
= _highp
) == 0) /*p1 is the only free block*/
68 /*search for the preceding free block*/
69 if (_lastp
< p1
) /*reduce search*/
74 /* if p2 preceeds p1 in the circular list,
75 * try to merge them */
76 p1
->next
= p2
->next
; p2
->next
= p1
;
77 if (p2
<= p1
&& merge(p2
,p1
))
80 /* p1 preceeds p2 in the circular list */
81 if (p2
> p1
) merge(p1
,p2
);
86 *pp
= (struct adm
*) 0;