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
Currently, when allocating an object that should be managed by the garbage collector, you can specify a function that will run to clean up before the object is freed. It is not, however, possible to customize how the object is marked.
To do this, you have to add a new branch to cb_value_mark, which won't work when extensions are available.
A new field could be added to cb_gc_header which is a function pointer to a function that will mark the object. The default (if the field is NULL) would be a function that does nothing. The downside is that every object will one pointer larger (which adds up). Unfortunately, it's not really feasible to put this function anywhere else. In Python, it could live in the type of the object, but since we don't have extensible types here, that wouldn't help much.
One alternative would be to define a struct like this:
And then every object would still have just one pointer, to an instance of this struct. In most cases I think this should be statically allocated. If any new fields are needed in the future they could be added to the struct type.
The downside here would be an extra level of indirection when collecting and marking the object, but that is probably more acceptable than every object be 4 or 8 bytes larger.
The text was updated successfully, but these errors were encountered:
Currently, when allocating an object that should be managed by the garbage collector, you can specify a function that will run to clean up before the object is freed. It is not, however, possible to customize how the object is marked.
To do this, you have to add a new branch to
cb_value_mark
, which won't work when extensions are available.A new field could be added to
cb_gc_header
which is a function pointer to a function that will mark the object. The default (if the field isNULL
) would be a function that does nothing. The downside is that every object will one pointer larger (which adds up). Unfortunately, it's not really feasible to put this function anywhere else. In Python, it could live in the type of the object, but since we don't have extensible types here, that wouldn't help much.One alternative would be to define a struct like this:
And then every object would still have just one pointer, to an instance of this struct. In most cases I think this should be statically allocated. If any new fields are needed in the future they could be added to the struct type.
The downside here would be an extra level of indirection when collecting and marking the object, but that is probably more acceptable than every object be 4 or 8 bytes larger.
The text was updated successfully, but these errors were encountered: