ddor254
ddor254

Reputation: 1628

dynamic and stack memory allocation done by the compiler?

I know there are several types of memory allocation. Taking C as language example, we have static allocation, stack allocation, heap allocation.

I understand that the static allocation is done by compiler, but the other two takes place on run time. Who is responsible for that, is it the Compiler, Process or the Operating System?

I'm basically asking if the compiler is involved in running a program?

Upvotes: 2

Views: 298

Answers (2)

Vaibhav N Naik
Vaibhav N Naik

Reputation: 358

Compiler is not involved in running a program. Its job is to build the program to a stage from where the linker can take it to create an executable or take to a engine that executes the code in case of a dynamic builder. It only checks for some protocols that have to be followed for a particular language.

Static allocation (storage space) depends on the files that are being linked to and the storage required by the static structures and variables in the code.

Dynamic allocation is taken by the memory management unit where the resources are been allocated to the task that is in the memory and that is where the heap allocation takes place during the runtime.

Upvotes: -1

corei11
corei11

Reputation: 153

OS is responsible for stack and heap memory allocation.

The OS allocate stack memory for every thread and the language runtime calls the OS for allocate heap memory.

Upvotes: 4

Related Questions