* Inhibiting heap compaction
@ 2006-06-02 19:39 Florian Weimer
2006-06-02 19:56 ` [Caml-list] " David MENTRE
2006-06-02 20:25 ` Olivier Andrieu
0 siblings, 2 replies; 4+ messages in thread
From: Florian Weimer @ 2006-06-02 19:39 UTC (permalink / raw)
To: caml-list
Is it possible to prevent the heap from being compacted, or pin
individual objects?
Suppose I write a C function C_func, which takes a string argument.
It passes that argument to some library function lib_func (which has
been written by a third party). bar invokes a C callback C_cb. In my
wrapper for Caml, C_cb invokes the Caml function cb. cb conses and
triggers heap compaction. After return from cb and C_cb, bar uses the
old address of the string, which is incorrect.
Currently, I copy all strings used in such a scenario, but this adds
quite a bit of overhead.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Inhibiting heap compaction
2006-06-02 19:39 Inhibiting heap compaction Florian Weimer
@ 2006-06-02 19:56 ` David MENTRE
2006-06-02 20:25 ` Olivier Andrieu
1 sibling, 0 replies; 4+ messages in thread
From: David MENTRE @ 2006-06-02 19:56 UTC (permalink / raw)
To: Florian Weimer; +Cc: caml-list
Hello,
Florian Weimer <fw@deneb.enyo.de> writes:
> Is it possible to prevent the heap from being compacted, or pin
> individual objects?
You can prevent heap compaction:
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html#TYPEcontrol
mutable max_overhead : int; (* Heap compaction is triggered when
the estimated amount of "wasted" memory is more
than max_overhead percent of the amount of live
data. If max_overhead is set to 0, heap
compaction is triggered at the end of each major
GC cycle (this setting is intended for testing
purposes only). If max_overhead >= 1000000,
compaction is never triggered. Default: 500. *)
Use Gc.set to change those parameters.
Best wishes,
d.
PS: I think Lablgtk prevent heap compaction for similar reasons.
--
pub 1024D/A3AD7A2A 2004-10-03 David MENTRE <dmentre@linux-france.org>
5996 CC46 4612 9CA4 3562 D7AC 6C67 9E96 A3AD 7A2A
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Inhibiting heap compaction
2006-06-02 19:39 Inhibiting heap compaction Florian Weimer
2006-06-02 19:56 ` [Caml-list] " David MENTRE
@ 2006-06-02 20:25 ` Olivier Andrieu
2006-06-06 5:35 ` Florian Weimer
1 sibling, 1 reply; 4+ messages in thread
From: Olivier Andrieu @ 2006-06-02 20:25 UTC (permalink / raw)
To: Florian Weimer; +Cc: caml-list
Florian Weimer [Friday 2 June 2006] :
>
> Is it possible to prevent the heap from being compacted,
Yes. cf the function Gc.set
Gc.set { (Gc.get()) with Gc.max_overhead = max_int }
> or pin individual objects?
AFAIK, no
> Currently, I copy all strings used in such a scenario, but this
> adds quite a bit of overhead.
Mind that your strings need to be in the major heap for the
no-heap-compaction approach to work. To ensure this, your strings must
be long enough or you should call Gc.minor () before calling the C
function.
--
Olivier
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Inhibiting heap compaction
2006-06-02 20:25 ` Olivier Andrieu
@ 2006-06-06 5:35 ` Florian Weimer
0 siblings, 0 replies; 4+ messages in thread
From: Florian Weimer @ 2006-06-06 5:35 UTC (permalink / raw)
To: Olivier Andrieu; +Cc: caml-list
* Olivier Andrieu:
> Florian Weimer [Friday 2 June 2006] :
> >
> > Is it possible to prevent the heap from being compacted,
>
> Yes. cf the function Gc.set
>
> Gc.set { (Gc.get()) with Gc.max_overhead = max_int }
It looks as if it is possible to modify caml_percent_max directly from
C code. Hmm.
It would be better if C stack frames could be marked instead. That
way, the "no compaction, please" would be cleared automatically even
if exceptions are involved.
> > Currently, I copy all strings used in such a scenario, but this
> > adds quite a bit of overhead.
>
> Mind that your strings need to be in the major heap for the
> no-heap-compaction approach to work. To ensure this, your strings must
> be long enough or you should call Gc.minor () before calling the C
> function.
I had hoped to use Is_young to see if copying the object is still
necessary but it's not exported by the run-time library.
Well, looks as if I should defer this until copying is truly
unacceptable.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-06-06 6:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-02 19:39 Inhibiting heap compaction Florian Weimer
2006-06-02 19:56 ` [Caml-list] " David MENTRE
2006-06-02 20:25 ` Olivier Andrieu
2006-06-06 5:35 ` Florian Weimer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox