Re: Pascal compiler (was: Layout floating point numbers)

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2002-10-07 14:10:25

On Mon, Oct 07, 2002 at 12:35:16PM +0200, ruud.baltissen@abp.nl wrote:
> May I inform how CC65 handles the heap? The Idea I have is simple (at least
> that is what I think). The heap starts after the global variables unless the
> user tells something different. The first pointer pointer [1] points to the
> end of the reserved field + 1, the second one to the first pointer of the
> next field. If all reserved fields are successive, these two pointers are
> the same. If not, there is a gap that can be used.

I don't understand what you mean with "gap". In the standard configuration,
cc65 has the following memory stetup:

        +---------------+ <- Low memory
        |      Code     |
        +---------------+
        | Readonly data |
        +---------------+
        |      Data     |
        +---------------+
        |      BSS      |
        +---------------+
        .               .
        .   ..free..    .
        .               .
        +---------------+
        |     Stack     |
        +---------------+ <- High memory

The area between the BSS and the stack (shown above as free) is used as heap
if heap routines are used.

Programs may allocate arbitrary sized blocks from the heap. Allocated blocks
may be freed later. The heap routines manage a heap pointer that points to the
top of the heap and a free list, which is a list of blocks that are freed.

If a new block should be allocated, first the freelist is searched for a
matching block. If no matching block is found in the free list, the heap
pointer is increased.

If a block is freed, and this block is located at the top of the heap, the
heap pointer is decreased. Otherwise it is placed into the free list. When
placing the block in the free list, the routine checks to see if there are
adjacent blocks (maybe the block just below or above this one was already
freed before), so we can combine two or even three blocks to a larger one. To
help with combining blocks, the freelist (which is a double linked list of
blocks) is ordered by block address.

The original heap routine was written in C for a 32 bit microcontroller, and
later ported to C on the 6502. Some releases ago I've rewritten the routines
in assembler which helped a bit regarding size and speed.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de

       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail 2.1.4.