On 23/01/2016 07:41, Wolf wrote:
Hi,

I don't quite agree with Per's explanation, at least not as far as
SMSQ/E is concerned.

Once the memory is allocated, A0 points past the header, as Per said.

So, at -4(a0) you will find chp_flag, not chp_len.

Moreover, chp_flag is used by the system :

Consider how SMSQ/E releases memory reserved on the common heap
(in smsq_mem_rchp_asm)

         movem.l reglist,-(sp)           save volatiles
         moveq   #chp.free,d0
         move.l  d0,chp_ownr(a0)         set owner free
         move.l  chp_flag(a0),d0         flag address
         beq.s   mrc_rehp        is empty, do nothing
         move.l  d0,a1                   set flag...
         st      (a1)            ...now
*
So what happens here is that, if chp_flag isn't empty, the address
it points to will have its MSB set. If you put "grab" in there, then
address $67726162 will have its MSB set to 1.

OK, that most likely won't be a problem because in most cases that
address doesn't exist. But what if you put something else than "grab"
at chp_flag and that points to somewhere in real memory? Oops...

So your initial way of doing things definitely is the right way.


HTH

Wolfgang

No need to disagree, Wolfgang; a fact is a fact and the fact is I was wrong and you are right :)

As Tobias writes further on, the header of a heap is not described in the QDOS/SMS Bible, ie it is undocumented and should not be (mis)used.

However, I believe he may be confusing User Heap heaps (blocks allocated within a heap by MT.ALLOC(?)/sms.alhp) with general, Common Heap blocks. User Heap blocks have this 8 byte header, which is described in the document, in which the length and pointer may be discarded if not needed (but Ive never used this, because it is so poorly explained and documented). Regarding memory blocks reserved on the Common Heap with MT.ALCHP/sms.achp, they have the same 16 byte header in both QDOS and SMSQ.

In the documentation for SNG's DIY memory toolkit he says:

"System entries use all 16 bytes of the common heap header, but the last four bytes are unused if you allocate a block with MT.ALCHP. To help DISCARD to identify RESERVEd memory, the DIY Toolkit code stores the text 'Bufa' at the end of the common heap header, as a kind of 'watermark'."

It may well be that hp_rflag/chp_flag location is not used in QDOS (it doesnt appear to be so in Minerva 1.98, at least) but as Wolfgang demonstrates, it is used by SMSQ, and so it is a baaad idea to use this undocumented area, as Simon has done.

That being said, I thought the 'Q' in SMSQ stood for QL compatible and in particular: compatible with Quirky programmers! But this one must have slipped past TT, or have been deemed too useful to de-implement in SMSQ.

Anyways, apologies for any confusion I may have caused.

Per
_______________________________________________
QL-Users Mailing List

Reply via email to