Homework 5
- For the languages listed below, sketch the memory allocations
needed for a rectangular array of 2 rows and three columns.
Give the total amount of memory that is needed assuming that each element of
the array has size S and an object reference has size W.
- A static array in the C language which uses a direct representation.
- An array in a Java program where multidimensional arrays are represented
as arrays of arrays.
- Chapter 6, problem 10 - just do the access functions for column-major order.
- FORTRAN allows the programmer to create slices which take every
nth element from a one dimensional array starting with a
particular element (s). What would you use for the starting address
(sometimes called the virtual origin) and
element size in the descriptor for such a slice. Express your
answer in terms of the starting address of the original array,
the element size in the original array, the starting position s and
the spacing between elements. Assume that the elements of both arrays are indexed
from 0.
- Use the struct definition below to answer the following questions.
Assume that char and bool variables take 1 byte, int and pointer variables
take 4 bytes and double variables take 8 bytes.
typedef struct lexeme {
int token;
int intValue;
double doubleValue;
char * stringValue;} Lexeme;
- How much memory does a record of this type take up?
- Give the offset in bytes from the starting address of the record
for each element of the struct.
- Since the intValue, doubleValue and StringValue are never all used at
once, you could use a union inside the struct. Draw a sketch to show how the
data would be stored in this case. How many offsets are needed now?
This assignment can be turned in
- on paper (in class the day they are due)
- emailed to me (please use the address tcole@onyx.boisestate.edu)
with the assignment number in the subject and your name in
the text of the assignment.
- submitted using
submit tcole cs354 h5
Acceptable formats for electronically submitted assignments are text,
OpenOffice or MicrosoftWord. I should be able to open your assignment with
OpenOffice. Unless otherwise specified in the assignment, the entire
assignment should be in a single document.