Cheap and Secure Web Hosting Provider : See Now

# [Solved]: Number of addresses in a memory region

, ,
Problem Detail:

So I am looking at some Operating Systems exercises and we have

A swapping system eliminates holes by compaction. Assuming a random distribution of many holes and many data segments and a time to read or write a 32-bit memory word of 10 nsec, about how long does it take to compact 128 MB? For simplicity, assume that word 0 is part of a hole and that the highest word in memory contains valid data.

The solution is : `128 x 2^20 / 4 = 2^25` memory address

``      compaction time = (read + write) * # of memory access                       = 2 x 10 x 10 ^ -9 x 2^25                       = 671 ms ``

Problem is I dont understand the `128 x 2^20 / 4 = 2^25 memory address` part ? How did we get 2^20 in this case? I gues the 4 is 4 bytes =32 bits so I kinda understand that.

Now in `2 x 10 x 10 ^ -9 x 2^25` what is 2 here?

#### Answered By : Yuval Filmus

A megabyte is \$2^{20}\$ bytes.

The factor of \$2\$ is because we need to count both reads and writes.