Thursday, July 30, 2009

I have some trouble with my C homework...?

Assume the following behaviors in the virtual memory system. Reading or writing physical memory requires 25 nanoseconds. Reading or writing disk writing 25 milliseconds. Page size is 8 kilobytes. Presume that the program has 1 megabyte of physical memory available. You may consider everything except the array access itself to take no time. You should also assume that the first 1 megabyte of the array is in physical memory initially.





How long does each of the two following functions take to execute?





Both use the same array declared as:





static int data[256*256*8];


void function1()


{


int i;


int j;


for (i = 0; i %26lt; 32; i++)


for (j = 0; j %26lt; 512; j++)


data[j] = i;


}





void function2()


{


int i;


int j;


for (i = 0; i %26lt; 32; i++)


for (j = 0; j %26lt; 512; j++)


data[j*2048] = i;


}





More important than the answer is how I get to the answer, but anything helps.

I have some trouble with my C homework...?
Once your program consumes more than 1 MB of memory, then the operating system will page the remainder into memory. At that point, for each 8 kb of data you need, you have to incur a 25 ms penalty, since thats the time to read in 1 page of memory, and you can't read in less than 1 page at a time.
Reply:function1 needs to access 16MB , 1MB is already in memory, for next 1MB you need to first bring it to physical memory , think not that difficult.


No comments:

Post a Comment