This is the mail archive of the
mailing list for the Guile project.
Re: Confusion on scm_make_smob_type
>> 1. An smob for a C struct. No pointers to malloced memory.
>> 2. An smob for a pointer to a malloced C struct.
MD> I don't understand the difference between these two.
MD> Aren't C structs always malloc:ed when you use them as smobs?
MD> What would the alternative be?
I thought, from reading the documentation on scm_make_smob_type, that
I could get SCM_NEWSMOB to allocate the structure for me. It says "If
SIZE is 0, then no memory will be allocated when instances of the smob
are created, and nothing will be freed by the default free function."
From that I concluded that setting SIZE to sizeof(my_struct) would
make a scm_must_malloc for me.
The difference in the examples would then be that in the first case,
guile would be aware of all memory claimed by the smob, while in the
second second case, I would set one of the fields in the already
malloced structure to point to some other data.
But nevermind, I now understand that SCM_NEWSMOB do not allocate
memory. Which is fine.
MD> If you don't have any SCM objects in your malloc:ed memory block, you
MD> also get a free constructor. In this case, the following two lines is
MD> all you have to do:
MD> SCM type = scm_make_smob_type ("my-type", SIZE);
MD> SCM my_smob = scm_make_smob (type);
Cool, this is simple and nice. However, I notice that scm_make_smob is
not documented in data-rep.info.
Lars Arvestad Dept. of Numerical Analysis and Computing Science
Royal Institute of Technology (KTH), Stockholm, Sweden