4 * Ullrich von Bassewitz, 11.08.1998
14 void free (void* block)
15 /* Release an allocated memory block. The function will accept NULL pointers
16 * (and do nothing in this case).
24 /* Allow NULL arguments */
29 /* Get a pointer to the real memory block, then get the size */
30 b = (unsigned*) block;
33 /* Check if the block is at the top of the heap */
34 if (((int) b) + size == (int) _hptr) {
36 /* Decrease _hptr to release the block */
37 _hptr = (unsigned*) (((int) _hptr) - size);
39 /* Check if the last block in the freelist is now at heap top. If so,
40 * remove this block from the freelist.
43 if (((int) f) + f->size == (int) _hptr) {
44 /* Remove the last block */
45 _hptr = (unsigned*) (((int) _hptr) - f->size);
46 if (_hlast = f->prev) {
47 /* Block before is now last block */
50 /* The freelist is empty now */
58 /* Not at heap top, enter the block into the free list */