Calculating Page Table Size

Since we have a virtual address space of 2^32 and each page size is 2^12, we can store (2^32/2^12) = 2^20 pages. Since each entry into this page table has an address of size 4 bytes, then we have 2^20*4 = 4MB. So the page table takes up 4MB in memory.

malloc for struct and pointer in C

No, you’re not allocating memory for y->x twice. Instead, you’re allocating memory for the structure (which includes a pointer) plus something for that pointer to point to. Think of it this way: So you actually need the two allocations (1 and 2) to store everything. Additionally, your type should be struct Vector *y since it’s a pointer, and you should never cast the return value … Read more