Whenever we load a process (which consists of object code, static and global variables, stack and heap space) into main memory it would be of fixed size. But, the program doesn't know in advance how much heap memory is it gonna need? Is there some fixed stack and heap space given to each process of some size in advance? But, then wouldn't it be a waste of space to give same amount of stack and heap space for each process ?
There can be other possibility that whenever we execute malloc, operating system gives us free space (basically holes) from main memory which is not the part of process. So, process size can increase at runtime. Then, Why is stack and heap space given to a process in the first place?