[m-users.] How to write stack-friendly mercury-code?
Julien Fischer
jfischer at opturion.com
Tue Mar 29 15:58:07 AEDT 2016
On Mon, 28 Mar 2016, Paul Bone wrote:
> + Use a segmented stack
>
> If you use --stack-segments (an stseg grade component, compatible with
> low level C grades) then a segmented stack will be used, a segmented
> stack grows and shrinks as necessary. Unbounded recursion can now cause
> your computer to thrash, rather than just crashing your program. This
> is the easiest option, but it doesn't reduce your program's memory usage.
> It's a good option if the limit is the size of the stack, and not how
> much RAM you have.
>
> + Increase the size of the stack.
>
> In low-level graces, like asm_fast, put MERCURY_OPTIONS="--detstack-size
> N" in your environment. Check the Mercury user's guide.
For completeness:
In high-level C grades, Mercury programs just use the normal C stack. On
Unix-like platforms on you can adjust this using ulimit. On Windows,
you can use mmc's '--cstack-reserve-size' option to set the stack size
at compile time. (Alternatively, if you have Microsoft's dev tools
installed you can use the editbin utility to modify the size.)
Julien.
More information about the users
mailing list