代做Homework #3: Introduction to Computer Systems - 18x13: Summer 2024调试数据库编程
- 首页 >> Database作业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.