Re: Q: Linux system capacities on data structures.

From: Robert Vazan (robertvazan_at_privateweb.sk)
Date: 08/01/03


Date: 1 Aug 2003 07:40:40 GMT

In comp.programming Kasper Dupont <kasperd@daimi.au.dk> wrote:
> Robert Vazan wrote:
>>
>> AFAIK, some Unices might segfault your program if stack grows too fast.

> Too fast?

Too big steps. I admit this info came from MSDN...

>> Think that arrays grow upwards while stack grows downwards. When you
>> write to first element in your array, it's eight megabytes away from
>> last allocated page of stack. Linux probably allocates stack
>> continuously and allocating eight megabytes at once is probably too
>> much.

> The distance to the last allocated page is not an issue. You are not
> allowed to access stack below the stack pointer, but if you first move
> the stack pointer multiple megabytes down, the area in between that
> and the existing stack is valid.

Changes to stack pointer cannot be trapped by kernel, so what you
describe cannot be implemented. AFAIK, stack is allocated upon page
fault which happens the moment you access memory through the stack
pointer. Stack is normally continuous, but it is possible to request
page that is distant from currently allocated pages. Kernel can do about
three things: allocate just this page, allocate continuous sequence, and
segfault the program.

> However there is an upper limit to
> the size of the stack, by default this limit is 8MB.

Yes, setrlimit() would help, but using heap is simpler.