On Fri, 15 Feb 2008, Marek Paliwoda wrote:
> >Marek you said that you are using mark/sweep functions extensively.
> >Is it only for marking external HB_ITEMs or for sth else.
> You probably misunderstood me, or I was not clear enouch responding
> to Mindaugas. In a post to Mindaugas I was refering to your proposition
> of changing the following code :
>       ptr = hb_gcLock( hb_gcAlloc( ptr ) );
>       <initialization code>
>       hb_itemPutPtrGC( ptr, destructorFunc );
>       hb_gcUnock( ptr );
> to
>       ptr = hb_gcAlloc( ptr );
>       <initialization code>
>       hb_itemPutPtrGC( ptr, destructorFunc );
> Mindaugas responded that he supports such a decision because
> the small amount of publicly available code uses this feature,
> and I posted an info that I am using it for quite a long time.
> Honestly speaking I did not use gcLock()/gcUnlock() pair, but
> fortunately to me I was using gcAlloc()/itemPutPtrGC()/itemRelease()
> thru MACROS, so it was an immediate fix to do it well :). Using
> MACROS in my case, also causes that your proposition will not hurt
> me at all too, so I am all for it and I support it :).

Fine so probably I'll change it. The counter in GC and FM blocks will
be initialized to 0 and increased in hb_itemPut*() (it will affect also
strings), GC blocks will be locked by default and unlocked in
hb_itemPutPtrGC()

> I was not reffering to using hb_gc(Un)RegisterSweep(), especially
> to protect pure GC blocks, because unlike you, I cannot imagine
> any funcionality where such a feature could be utilized, as oposed
> to returning such a block to PRG level and to store it there. I'd
> greatly appreciate if you could post any example of such a funcionality.

If we are talking about protecting single GC block then now registering
and unregistering mark/sweep function costs exactly the same as calling
hb_itemNew()/hb_itemRelease() for GC block holder - internally it makes
very similar operations.
This function can be usable if you will have many GC blocks not attached
to any item but to other GC blocks with cross references. The allocated
GC blocks are shared so can be attached to more then one GC block.
Such code should use hb_gcIncRef()/hb_gcDecRef() for attaching/detaching
GC blocks to its internal structures and also hb_gcMark() inside registered
mark/sweep function to mark its active GC blocks as used.
It can be very complicated structure with many GC blocks and only few
of them will be attached to HVM items. But if no one so far created such
code then maybe I should not document it ;-) because similar effect
can be reached without mark/sweep function though with some small overhead:
hb_itemNew() used as block holder.

best regards,
Przemek
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to