On 22/01/2016 19:21, Marcos Cruz wrote:
<>
----
moveq #24,d0 MT.ALCHP
trap #1 Allocate RAM
tst.l d0
bmi.s return_fp Return error code
move.l #'Bufa',-4(a0) Identify this block
----
This uses the long word below the address of the free space, just
returned by the trap. My doubt is: Why is that lower space supposed to
be free? It may belong to a previous allocated space, or to a node of
the heap structure. Am I missing something? Is there a "safe gap"
between allocated spaces? So far I've not found this information in the
low-level documentation I have. Norman Dumbar includes similar code in
his Programming Series, but of course without the checking marker.
Whenever the user requests a block of memory in the Common Heap, the
request is rounded up to the nearest 8 bytes and a 16 byte header is
added. The header looks like this:
chp_len equ $0000 long LENgth of space in common heap,
including header
chp_drlk equ $0004 long pointer to DRiver LinKage (allocated
space)
chp_nxfr equ $0004 long rel pointer (-4) to NeXt FRee space
(free_space)
chp_ownr equ $0008 long OWNer job id (-1 if not owned)
chp_flag equ $000c long address of FLAG byte, set when space
released
chp_end equ $0010
The address returned in register a0 by the MT.ALCHP/sms.achp call
points past this header to the start of the usable area, so relative
to this, chp_len is located at -4(a0).
As this location is not currently used by the system for any other
purpose, some programmers have put it to other use. I guess, by now,
it must be considered to be convention that this space it "not used"
Per
_______________________________________________
QL-Users Mailing List