Open In App

How can the stack memory be increased?

Improve
Improve
Like Article
Like
Save
Share
Report

A Stack is a temporary memory address space that is used to hold arguments and automatic variables during the invocation of a subprogram or function reference. The size of this stack is called the stack size.

        Stack       

⤓
⤒

Heap

BSS

DATA

TEXT

How to increase stack size? One cannot increase the stack size. The reason of this is as mentioned below:

Reason:

The stack for a given interaction has a restricted, fixed size. Also, the stack must be contiguous. If the stack size is expanded continuously, the stack develops toward the heap memory and at a certain point, it will be touching the heap memory. In this way, when the stack arrives at the heap memory, no expansion is conceivable.

Methods of allocating stack size:

There are a number of different methods used. They are:

1. Dynamic:

The stack develops downwards, the heap develops upward. In event of a page fault fairly underneath the bottom end of the stack, the missing middle pages are allocated and mapped. Successfully expanding the stack from the top towards the base naturally. There is normally a most extreme up to which such allocation is done, which can or can not be determined in the climate, or powerfully changed by the program through a framework call. This varies heavily between different OS.

2. Fixed size:

Individual control tasks get fixed stacks). Additionally for this situation, the memory may be assigned just virtually, until truly required.

3. Pagewise:

These allocate and expand the stack dynamically as required. But this allocation is done not as a single contiguous portion, but rather as a connected chain of multi-page pieces. It requires different function entry/exit codes to be created by the compiler(s), to deal with fragment limits. Subsequently, such functions are commonly carried out by a language support system and not the actual OS.


Last Updated : 12 Jul, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads