On Linux/OSX, stack limit is get/set-able.  See eg:

http://stackoverflow.com/questions/7535994/how-do-i-find-the-maximum-stack-size

http://stackoverflow.com/questions/2279052/increase-stack-size-in-linux-with-setrlimit

also see "soft limit" and "hard limit" mentioned in post

On 18 May 2016 at 07:17, Henry Rich <henryhr...@gmail.com> wrote:

> 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
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to