This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Confusion on scm_make_smob_type


Lars Arvestad <arve@nada.kth.se> writes:

> I would really appreciate two very simple examples:
>   1. An smob for a C struct. No pointers to malloced memory.
>   2. An smob for a pointer to a malloced C struct. 
> I know how to do this (or think I do!), but I don't understand what I
> can get for free from libguile. What is the most simple way to do
> this?

I don't understand the difference between these two.
Aren't C structs always malloc:ed when you use them as smobs?
What would the alternative be?

One thing you get for free when you give a SIZE argument to
scm_make_smob_type is the default free function.  (free has to tell
Guile (by its return value) how much memory was freed).

If you don't have any SCM objects in your malloc:ed memory block, you
also get a free constructor.  In this case, the following two lines is
all you have to do:

SCM type = scm_make_smob_type ("my-type", SIZE);
SCM my_smob = scm_make_smob (type);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]