联系方式

您当前位置:首页 >> Database作业Database作业

日期:2024-06-15 12:21

Homework #3: Introduction to Computer Systems - 18x13: Summer 2024

Question 1        4 / 4 pts

Arrays Sizes (4 points)

Consider the following definitions in an x86-64 system with 8-byte pointers and 2-byte shorts. Answer with only a decimal number

Definition A Definition B

short numbersA[ 4 ][ 1 ][ 3 ];               char *numbersB = numbersA;

(2 point): How many bytes are allocated to numbersA? (Write “UNKNOWN” if not knowable):

24                   Bytes

Hint: Think sizeof()

(2 point): How many bytes are allocated to numbersB? (Write “UNKNOWN” if not knowable):

8                      Bytes

Hint: Think sizeof()

Question 2        2 / 2 pts

Array Arithmetic

(2 points): Consider the following definitions as implemented on a shark machine, i.e. x86-64. What is the difference, i.e. number of bytes, between numbers[ 1 ][ 2 ] and numbers[ 2 ][ 1 ]? 8 bytes

Definition A

short numbers[ 3 ][ 5 ];

Question 3       6 / 6 pts

Structs and Alignment (6 points)

For this question please assume “Natural alignment”, in other words, please assume that each type must be aligned to a multiple of its data type size.

Please consider the following struct:

struct {

char c;    // 1-byte type

double d;   // 8-byte type

short s2;    // 2-byte type

} struct_t;

Then, in the scratch space below (or in your head), rewrite the struct to minimize internal fragmentation, i.e. padding.

Finally, consider the following assignment:

x = sizeof(struct struct_t);

(A) (3 points): Consider the original version of the struct, the value of x is 24 Bytes.

(B) (3 points): Consider the version of the struct that you created, the value of x is 16 Bytes.






版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:821613408 微信:horysk8 电子信箱:[email protected]
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:horysk8