Re: Memory management by Share[]?
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: Memory management by Share[]?
- From: twj
- Date: Tue, 6 Oct 92 18:02:16 CDT
>Share[] seems like a command you would want to execute in your
>init.m file, since it promises to significantly reduce memory
>requirements; in fact you would expect it to be built into the
>kernel and not under user control. Thus it must be dangerous;
>indeed there is a remark about "the sharing of subexpressions is
>often destroyed as soon as you use an operator like /.". Does
>anyone have any experience with Share[]? Why doesn't everyone use
>it?
Share[] IS built into the Kernel and it is also under user control.
What Share[] does is to go through and compare every expression which
can be accessed from the symbol table. When it finds two
expressions which are the same it eliminates one of them and copies
the references over to point to the other one. There is no
circumstance in which this is unsafe.
Putting Share[] into your init.m will help reclaim memory which was
used at initialisation time, but you should call it after everything
which has consumed memory. Thus you could call it after loading the
Integration packages or other big packages.
It would be good to build it into the memory allocator so that every
time the memory in use goes up by a certain amount it gets called
automatically. However why should this be put into C since it can be
done quite happily at top-level?
Put this in your init.m and it will be called automatically.
$Post :=
(If[ MemoryInUse[] - $MemoryUsed > $MemoryIncrement,
Message[ Share::prog, Share[]];
$MemoryUsed = MemoryInUse[]];#)&
$MemoryUsed = MemoryInUse[]
$MemoryIncrement = 100000
$MemoryIncrement::usage =
"The value of $MemoryIncrement determines how much
MemoryInUse[] has to increase for Share[] to be called
automatically."
Share::prog =
"Share[] has been called automatically and `1` bytes have
been reclaimed."
I just thought of this now. Why did'nt I think of it before?
Tom Wickham-Jones
WRI