1 /* $Id: phys.c,v 1.2 1994/06/24 11:55:35 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
12 /* Physical manipulations.
13 The blocks concerned are not in any logical chain.
17 create_chunk(void *p, size_t n)
19 /* The newly acquired piece of memory at p, of length n,
20 is turned into a free chunk, properly chained in the
22 The address of the chunk is returned.
25 /* All of malloc memory is followed by a virtual chunk, the
26 mallink of which starts mallink_size() bytes past the last
28 Its use is prevented by testing for ml == ml_last first.
30 register mallink *last = ml_last;
32 assert(!last || p == (char *)phys_next_of(last) - mallink_size());
33 ml = (mallink *)((char *)p + mallink_size()); /* bump ml */
35 started_working_on(ml);
37 set_phys_prev(ml, last);
40 set_phys_next(ml, (mallink *)((char *)ml + n));
42 assert(size_of(ml) + mallink_size() == n);
43 if (last && free_of(last)) {
44 coalesce_backw(ml, last);
47 check_mallinks("create_chunk, phys. linked");
52 truncate(register mallink *ml, size_t size)
54 /* The chunk ml is truncated.
55 The chunk at ml is split in two.
56 The remaining part is then freed.
58 register mallink *new = (mallink *)((char *)ml + size);
59 register mallink *ph_next = phys_next_of(ml);
63 set_phys_prev(new, ml);
64 set_phys_next(new, ph_next);
66 if (! last_mallink(ml)) {
67 set_phys_prev(ph_next, new);
68 calc_checksum(ph_next);
69 if (free_of(ph_next)) coalesce_forw(new, ph_next);
72 set_phys_next(ml, new);
75 started_working_on(new);
77 stopped_working_on(new);
78 check_mallinks("truncate");
82 combine_chunks(register mallink *ml1, register mallink *ml2)
84 /* The chunks ml1 and ml2 are combined.
86 register mallink *ml3 = phys_next_of(ml2);
88 set_phys_next(ml1, ml3);
90 if (!last_mallink(ml2)) {
91 set_phys_prev(ml3, ml1);