0

I am mainly thinking about Windows.

AFAIK on such platforms there are many stacks, each program, or maybe even each thread has its own stack, and each of such threads can push bytes onto it - AFAIK every of such push should be checked in runtime in case of stack overflow - so it seem it is some cost related to each and every push (something like arrays bounds checking) - how exactly this checking is implemented ?

On old machines as I remember there was no checking but some fff become 000 so there was no cost of checking, but today on windows platform it seem to me that probably every stack is bound checked - but I do not know how it is implemented.

Kara
  • 6,115
  • 16
  • 50
  • 57
grunge fightr
  • 1,360
  • 2
  • 19
  • 38

1 Answers1

1

I'm not aware of any fully-compiled language on Windows or Linux platforms that does call stack bounds checking by default. Thus, overflowing the available stack space leads to a segmentation fault as described in (for instance) the questions Segmentation fault due to recursion and What is the difference between a segmentation fault and a stack overflow?.

The benefit of not doing bounds checking, as observed in the question is that the code runs more quickly. If one wanted to bounds check for some particular reason, one could insert the bounds checks for that specific case.

Community
  • 1
  • 1
Simon
  • 10,679
  • 1
  • 30
  • 44