Date: Thu, 03 Mar 2005 18:52:21 +0900 (JST) Message-Id: <20050303.185221.74722842.garrigue at math.nagoya-u.ac.jp> To: robertr at rftp.com Cc: lablgtk at math.nagoya-u.ac.jp Subject: Re: Relationship to OCaml GC From: Jacques Garrigue In-Reply-To: <422670EA.6070701 at rftp.com> References: <422670EA.6070701 at rftp.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit From: Robert Roessler > The following [dire] warning appears both in the LablGTK README as > well as in the "OCaml-ized" GTK+ 2.0 tutorial: > > "IMPORTANT: Some Gtk data structures are allocated in the Caml heap, > and there use in signals (Gtk functions internally cally callbacks) > relies on their address being stable during a function call. For this > reason automatic compaction is disabled in GtkMain. If you need it, > you may use compaction through Gc.compact where it is safe (timeouts, > other threads...), but do not enable automatic compaction." > > 1) I see the "disabling" in gtkMain... > 2) is this still an issue? > 3) if so, why the was Caml heap used for these structures rather than > the malloc heap? > 4) is this "non-compaction" not an issue in "real" usage of LablGTK? > Or do all non-trivial apps end up forcing the compactions during the > "safe" times? This is still true. The reason to do that is to avoid extra memory management. When a pointer is in the old heap, only compaction may move it, and compaction is supposed to be rare. So assuming that it will not move during a short callback makes things simpler. I don't think the compaction issue should be a problem in practice. You only need it when you allocate lots of memory, and in irregular sizes, so that it becomes difficult to reuse collected areas. Another example one can think of is making a computation using lots of memory, and then discarding the data structures and being quiet for a while. In the first case you probably want to do the compaction when the application is idle. In the second one, you want to force compaction manually, when you know that you've freed lots of memory. Jacques