This is the mail archive of the
mailing list for the Guile project.
Re: New smob interface
Mikael Djurfeldt <firstname.lastname@example.org> writes:
> So, the question is how to handle situations when the user application
> wants to allocate memory.
> I guess there are two options:
> 1. Specify size 0 in this case, so that the GC never is aware of this
> 2. Tell the GC about foreignly allocated memory. This could either be
> made through a dedicated call/macro or implicitly in a sibling
> function to scm_make_smob which takes two args, the second being a
> pointer to the data allocated.
I think I know how I'd like things to be (again with some emphasis on
simplicity of implementation and efficiency; a more user-friendly
interface to creating new data types can be supplied on the gh level):
The user has two decisions to make
1. Do I want to allocate and free mallocated memory myself?
Yes => specify size 0 as second arg to scm_make_smob_type
No => specify size of smob data struct
2. Do I have SCM objects in my struct which are handled by the GC?
Yes => use SCM_NEWSMOB
No => use scm_make_smob
In the docs for scm_make_smob_type one could say something like:
"SIZE is the amount of memory allocated/freed by Guile, either through
scm_make_smob/the implicit free function or through
scm_must_malloc/scm_must_free. If the user chooses to allocate and
free malloced memory himself, he should specify 0."