The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+12 votes
895 views

A language $L$ allows declaration of arrays whose sizes are not known during compilation. It is required to make efficient use of memory. Which one of the following is true?

  1. A compiler using static memory allocation can be written for $L$
  2. A compiler cannot be written for $L$; an interpreter must be used
  3. A compiler using dynamic memory allocation can be written for $L$
  4. None of the above
asked in Compiler Design by Veteran (59.5k points)
edited by | 895 views

1 Answer

+19 votes
Best answer

C.

Using dynamic memory allocation, memory will be allocated to array at runtime.

answered by Boss (19.7k points)
edited by
+1
@Arjun And allocation will be done in heap memory or stack memory ??
+1
During runtime, it is difficult to do anything on stack- as activation record size is decided at compile time. So, it must always be on heap. But I don't know if any language does this on stack.
0
If activation record size is known at compile time. Then why can't we place it in the area where static or global variables is placed ?? why do we need heap for it ??
0
Or you want to say there may be need of some dynamic allocation inside the activation record. So we allocate it to heap area.
+4
Static and global memory area is compile time determined and this is part of the binary. At run time, we cannot change this. Only memory area freely available for the process to change during runtime is heap.
+1
Then how static area and stack area differs ?? Does stack area not freely available during run time ??
+6
Activation records are created on stack. These are created and destroyed during program run- that is stack area changes its size during program run. But static memory area remains constant.

Even though memory on stack area is created during run time- the amount of memory (activation record size) is determined at compile time. For static area, the memory is determined during compile time and this will be present as soon as program is loaded.  

This is with respect to a simple programming language like C.
0
@arjun  sir plz verify is it   the diffrence b/w heap area and stack area ??    the memory allocated  in the stack area is based on the amount memory required for activaction record size and this will be done at compile time . and that's why  here is limitation to  allocate the memory on stack area bcz its totally  depend on what memory assign for activaction record size at compile time  . but in case of  heap  we also allocate the memory on run time but here freely we allocate without any limitation .
+7
Yes, but stack is a runtime entity. At compile time compiler only reserves the stack space for activation record. This gets used (allocated on actual memory) only during program run. Only DATA segment part of the program like static variables, string literals etc. are allocated during compile time. For heap area, how much memory to be allocated is also determined at run time.
+2
on static memory allocation is used for  global variable and allocate during compile time and never gona be change during run time. and for stack we determine the memory  require of activation record at compile time and this will be allocate during run time and for heap memory is determines  and  allocate at run time only


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

39,512 questions
46,664 answers
139,703 comments
57,481 users