Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Array Question 5. 16 points] Suppose we are compiling for a machine with 1-byte

ID: 3704823 • Letter: A

Question

Array Question

5. 16 points] Suppose we are compiling for a machine with 1-byte characters, 2-byte shorts, 4- every byte integers, and 8-byte reals, with alignment rules that require the address of primitive data element to be an even multiple of the element's size. Consider the following arrav: A array [0..9] of record s: short j: integer c: char d: real h: char f real t: short i: integer e: char a. Suppose that you cannot reorder fields. Show the layout of a single record in the above array. How much space will be consumed by the array? b. Suppose that you can reorder fields. Show the improved layout of the record that uses the least amount of space while obeying alignment rules. How much total space will be saved with this new layout for the entire array?

Explanation / Answer

Solution:

a)

If we cannot reorder fields then the layout will look like this,

since there is nor ordering we must allocate the maximum possible value to the cells in the array.

Total size consumed= 9*8 = 72 bytes

b)

In case of ordering we will allocate the data to the char first then shorts, then int and finally real then we can give variable size partitions in the array as expressed in the problem statement.

the size here will be 3 + 2*2 + 4*2 + 8*2 = 3 + 4 + 8 + 16 = 31 bytes

72-31 = 41 bytes has been saved.

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

s 2 j 4 c 1 d 8 h 1 f 8 t 2 i 4 e 1
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote