Frage

The answer probably differs depending on the OS, but I'm curious how much stack space does a thread normally preallocate. For example, if I use:

push rax

that will put a value on the stack and increment the rsp. But what if I never use a push op? I imagine some space still gets allocated, but how much? Also, is this a fixed amount or is does it grow dynamically with the amount of stuff pushed?

War es hilfreich?

Lösung

POSIX does not define any standards regarding stack size, it is entirely implementation dependent. Since you tagged this OSX, the default allocations there are :

  • Main thread (8MB)
  • Secondary Thread (512kB)

Naturally, these can be configured to suit your needs. The allocation is dynamic :

The minimum allowed stack size for secondary threads is 16 KB and the stack size must be a multiple of 4 KB. The space for this memory is set aside in your process space at thread creation time, but the actual pages associated with that memory are not created until they are needed.

There is too much detail to include here. I suggest you read :

Thread Management (Mac Developer Library)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top