This is the mail archive of the guile@sources.redhat.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: Scm_sloppy_assq mostly fixed, still real slow


Han-Wen Nienhuys <hanwen@cs.uu.nl> writes:

[Sorry for commenting on this so lately.  Maybe this question is out
 of date by now.]

> To shed some further light on Lily's memory handling: Most smobs in
> lily smobify and protect themselves, i.e.
> 
>      Obj::Obj ()
>      {
> 	self_scm_ = smobify_self();
> 		  scm_protect_object (self_scm_);
> 		  }
> 
> later on, the smob is put into a big scheme list representing the
> score and the object is unprotected,
> 
>       list_ = gh_cons (obj->self_scm_, list_);
>       scm_unprotect_object (obj->self_scm_);
> 
> This used to be quite efficient because there was little
> time betweeen protect and unprotected (so unprotected would find the
> object quickly, in front of the list.)
> 
> It is done in this way, because there might very well be some time
> between creation ("new Obj") and list-adding, in which a GC would kill
> an object that wasn't yet added to the score list.

I think you should avoid calling scm_protect_object.

There are many ways to achieve this.  Two ways could be:

1. Smobify the object outside of the object, when putting the object
   in the Scheme list.

or

2. Since you are able to put the object in a Scheme list later, you
   are keeping the object in some kind of data structure S.  In
   addition to smobify_self (), you could have a mark_self () in every
   object.  If you protect the data structure S, the mark function for
   S could call mark_self () in every object in S.

Best regards,
/mdj

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