TOOLS AND TECHNIQUES FOR COMPILER DESIGN
MISCELLENOUS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
Stack
|
|
Heap
|
|
Both
|
|
None of the above
|
Detailed explanation-1: -Quoting from Jeff Hill’s answer: The stack is faster because the access pattern makes it trivial to allocate and deallocate memory from it (a pointer/integer is simply incremented or decremented), while the heap has much more complex bookkeeping involved in an allocation or free.
Detailed explanation-2: -Static memory allocation is efficient because it allocates memory to the process before it starts running. Therefore, the program runs faster because there is no overhead of memory allocation operations while the program is running.
Detailed explanation-3: -Because the heap is a far more complicated data structure than the stack. For many architectures, allocating memory on the stack is just a matter of changing the stack pointer, i.e. it’s one instruction.