This is the mail archive of the guile@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: New smob interface


Klaus Schilling <Klaus.Schilling@home.ivm.de> writes:

> Greg Harvey writes:
>  > Mikael Djurfeldt <mdj@nada.kth.se> writes:
>  > > But, we never told it that sizeof (WINDOW) bytes was allocate in the
>  > > first place!  This is normally handled inside scm_must_malloc.  (All
>  > > Guile objects have their storage allocated using that call.)
>  > 
>  > Here you should use scm_done_malloc. There should also be a
>  > scm_done_free call, so that you don't have to return the size freed to
>  > the gc, which can be unwieldy if you have a large, dynamic
>  > structure (I think it's a bit gross, anyway ;). 
> 
> Where should those routines be placed? Immediately after the function
> that allocates/frees a struct which gets wrapped into a smob
> returns?

Yep. You want to do something like:

create_foo_obj(foo);
scm_done_malloc(sizeof(foo_obj), "create_foo");

destroy_foo_obj(foo);
scm_done_free(sizeof(foo_obj));


> Before or after a gh_allow_ints()? (If it really makes sense to call
> gh_defer_ints before)

Shouldn't make any difference, except that if it's not in a
defer_ints, the done_malloc can trigger a gc.

-- 
Greg

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