Hi,
No. In fact it's minor modification. It will be enough to initialize
referece counter with 0 and add hb_xRefInc() in hb_itemPut*() functions.
But this modifications should be bound with yet another one (see below).
I was thinking about it, but I didn't know that GC pointers can be
locked, to avoid freeing it between hb_gcAlloc() and hb_itemPut*().
BTW, you've wrote "hb_itemPut*()". Do you mean the same modification for
hb_itemPutCPtr()? It seems, the same approach will also work. We just
do not need locking, because FM memory is not collected by GC.
And hb_gcAlloc() is sth what should be modified yet. This function
returns pointer which is not locked (hb_gcLock()/hb_gcUnlock()) and
can be freed by GC if we do not lock it or attach to GC known item.
When we add automatic GC call then it may be a problem for some 3-rd
party code.
I think returning of locked GC pointer is very important in real
multitasking enviroment. Otherwise pointer could be released even if
code is:
ptr = hb_gcLock( hb_gcAlloc( ptr ) );
If you look at core code then you will find that I
intentionally changed the order of allocating data for arrays, hashes,
codeblocks and some collectible pointer items to eliminate potentially
danger situations. I know how it should be done and it was easy for me.
But it may be serious problem for 3-rd party code developers who do
not know details of our HVM and GC and when/where it can be automatically
activated in the future. ...
IMHO hb_gcLock() should return LOCKED pointer and hb_itemPutPtrGC() should
unlock it automatically and increase reference counter (modification above).
In such case the same code will look like:
ptr = hb_gcAlloc( ptr );
<initialization code>
hb_itemPutPtrGC( ptr, destructorFunc );
I think that it will greatly reduce possible mistakes and also your
first example will work as you wanted. hb_gcLock()/hb_gcUnlock() are
a little bit too low level for me if possible then they should be
eliminated from 3-rd party API.
Opinions? Ryszard you are original author of hb_gc*() functions.
What do you think about it.
Yes, I think it's a good idea. We do not have many problem with GC in
3rd party software, because nobody are using collectible pointers yet,
but it can be a problem later. So, it's good chance to avoid it from the
beginning.
Best regards,
Mindaugas
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour