Yes, I can find out how much stack I have used; I just don't know how to
find out what the limit is, or even if there is a limit (some systems
seem to extend the stack dynamically). If you know of a fairly
system-independent way to find out, I'd like to hear it.
Henry Rich
On 5/17/2016 10:16 AM, Raul Miller wrote:
Hypothetically speaking, you should be able to determine something
about the stack by examining the address of a local variable which is
on the stack.
This gives a crude way of determining stack size: write a recursive
function which prints the address of a local variable (and flushes
that print buffer) then calls itself again. When the program crashes
you can inspect the starting and ending address and look at the
difference to determine the stack size. (And, unless someone got
fancy, you can check that all addresses in between have the same
address offset between them.)
(There might be other OS-specific or compiler-specific ways of
determining allocated stack size.)
Once you have an idea of stack size, it should be relatively simple to
put a check on stack size somewhere convenient (for example, memory
allocation - since that tends to be called in a lot of places). If
you've reached some threshold, have that routine (or those routines)
fail with a stack out-of-bounds error.
That said, some compiler optimizations might defeat this approach. If
those are detected, I guess they would need to be documented (in some
developer-oriented document - perhaps a README for the source).
I hope this helps,
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm