You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While looking at the GC stuff-code I saw this in blitz.mod/blitz_gc.c:
voidbbGCRetain( BBObject*p ) {
structretain_node*node= (structretain_node*)GC_malloc_uncollectable(sizeof(structretain_node));
node->count=1;
node->obj=p;
#ifdefBBCC_ALLOCCOUNT++bbGCAllocCount;
#endifbb_mutex_lock(bbReleaseRetainGuard);
structretain_node*old_node= (structretain_node*)avl_map(&node->link, node_compare, &retain_root);
if (&node->link!=&old_node->link) {
// this object already exists here... increment our reference countold_node->count++;
// unlock before free, to prevent deadlocks from finalizers.bb_mutex_unlock(bbReleaseRetainGuard);
// delete the new node, since we don't need itGC_FREE(node);
return;
}
bb_mutex_unlock(bbReleaseRetainGuard);
}
And I wondered, why we allocate GC managed memory even if we later find out, that we might not need the new "node" as there was already something referencing it.
Now compare this to bbGCRelease():
voidbbGCRelease( BBObject*p ) {
// create something to look upstructretain_nodenode;
node.obj=p;
bb_mutex_lock(bbReleaseRetainGuard);
structretain_node*found= (structretain_node*)tree_search((structtree_root_np*)&node, node_compare, (structtree_root_np*)retain_root);
if (found) {
// found a retained object!found->count--;
if (found->count <=0) {
// remove from the treeavl_del(&found->link, &retain_root);
// free the nodefound->obj=0;
// unlock before free, to prevent deadlocks from finalizers.bb_mutex_unlock(bbReleaseRetainGuard);
GC_FREE(found);
return;
}
}
bb_mutex_unlock(bbReleaseRetainGuard);
}
There we do NOT affect the GC just to allow the lookup.
As creating the "simple" struct might be less heavy .. isn't it possible to only call the GC stuff if really needed?
Edit: It seems to be made for "C(++) code" which wants to mark specific objects as "to keep". So it might only be used rarely (yet it could be ... redone avoiding GC affection)
The text was updated successfully, but these errors were encountered:
While this change would get rid of the "in all cases" kept GC_MALLOC_UNCOLLECTABLE it would at least temporary affect the GC even if in most cases not needed (exposing existing BlitzMax objects VS passing new and nowhere referenced BlitzMax objects).
Edit: Seems @woollybah exactly did the opposite already there: badcdc0
Maybe you (@woollybah ) could explain to me why this was needed?
While looking at the GC stuff-code I saw this in blitz.mod/blitz_gc.c:
And I wondered, why we allocate GC managed memory even if we later find out, that we might not need the new "node" as there was already something referencing it.
Now compare this to bbGCRelease():
There we do NOT affect the GC just to allow the lookup.
As creating the "simple" struct might be less heavy .. isn't it possible to only call the GC stuff if really needed?
Edit: It seems to be made for "C(++) code" which wants to mark specific objects as "to keep". So it might only be used rarely (yet it could be ... redone avoiding GC affection)
The text was updated successfully, but these errors were encountered: