Created 07/08/03

# on Dynamic Memory Allocation

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.

1. How much of the 4 gigabytes of virtual memory does a user program run in?

A. none of it
B. about one quarter
C. roughly half
D. all of it

2. If the maximum address is 0xFFFFFFFF, what address is half of that?

A. 0x0000FFFF
B. 0x77777777
C. 0x7FFFFFFF
D. 0xFFFF0000

3. What is it called when memory for a program is allocated as the program is running?

A. static memory allocation
B. dynamic memory allocation
C. stack memory allocation
D. virtual memory allocation

4. What segment of memory is used for the data that is statically declared in a program?

A. data segment
B. static segment
C. stack segment
D. heap

5. Which of the following code fragments requests 16 bytes of memory?

A.
    li      $a0, 16
    li      $v0,  9
    syscall
B.
    li      $a0, 16
    li      $v0,  9
C.
    li      $a1, 16
    li      $v1,  9
    syscall
D.
    li      $a0,  9
    li      $v0, 16
    syscall

6. With an actual operating system (not the simple trap handler of SPIM) is dynamic memory every returned to the system?

A. No. Memory can never be returned because that would leave inaccessible gaps.
B. No. Since there is an unlimited amount of virtual memory there is no reason to every give any back.
C. Yes. After being returned, it might be used again to satisfy another request for memory.
D. Yes. But once returned it is no longer available.

7. With an actual operating system, can the address of a block of dynamic memory be predicted before it is allocated?

A. No, because virtual memory addresses follow no order.
B. No, because the operating system uses complex algorithms to find an available block.
C. Yes, blocks are always allocated in sequential order.
D. Yes, because the program can request particular addresses.

8. Say that the base address of the following structure is in register $s8 and that the order of data in the structure has not been altered.

    struct
    {
      int   valA;
      int   valB;
      float rate;
    }

Which of the following code fragments loads $t0 with `rate`?

A.
    lw    $s8,8($t0)
B.
    li    $t0,8($s8)
C.
    lw    $t0,($s8)
D.
    lw    $t0,8($s8)

9. In a high level language like "C" is the actual byte-level layout of data in a struct exactly determined by its declaration?

A. No. Compilers are free to rearrange the order of variables and to insert extra bytes into the data.
B. No. The operating system may rearrange the order of the variables.
C. Yes. High level languages specify exactly how data is laid out at the byte level.
D. Yes. C, C++, and other languages lay out structures in exactly the same way.

10. The grouping of data that "C" calls a struct is called what in Pascal and COBOL?

A. object
B. entity
C. record
D. trace

The number you got right: Percent Correct: Letter Grade:

If you have returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the SHIFT KEY while clicking to clear the old answers.