Amazon Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
I'm not sure 100% what you want, but if you just open a file stream and read in what you need writing the content to the output file (I assume this is what you mean by split) until you find the break point. Then close the file you are writing to and open the next one. No need to do anything special as the OS is handling all the memory management for you.
Then again I could be very confused about what the problem is. Then again I remember when 128 MB of memory was a thing and virtual memory was worth it's weight it gold ;-)
it kind of depends also on what you want to do with the contents of the file. if you just want to read the file, read only the first few pages(OS memory pages) of the file. While the CPU is reading these pages and working on them, you can use double buffering to get next set of pages. When the third set of pages comes, it replaces the first set of pages, fourth set replaces the second and so on. You can also use triple buffering. if you require non-sequential reading of file, you can adapt a suitable page replacement policy.
I am not sure of the answer as much but this can be done as below:
- Shweta October 16, 2014physical memory = 20GB approx 2^35 addresses
logical memory = 2GB 2^31 addresses
To implement memory management so that the whole physical memory can be accommodated in logical memory on demand paging
We need to divide physical and logical memory into same and fixed size frames and pages respectively.
Size of page = size of frame = size of logical memory/no of pages = size of physical memory/ no of frames
2^31/x = 2^35 /y
y/x = 2^35 /2^31
y/x= 2^4/1
this means for every 16 frames we make in physical memory of size 2^31 each we make one page of same size
To optimize our page size in the range 2^9 to 2^14 bytes
We get y/x = 2^21/2^17 for page size 2^14 bytes
Hence we have now 2^21 frames and 2^17 pages with sizes 2^14 bytes each
Now , logical address of page = page_address_bits(n)+offset_bits(d) => 17 bits+14 bits =31 bits
Each page corresponds to a particular frame in page table so to address that frame is
physical address of frame = frame_address_bits(n)+offset_bits(d) => 21bits+14 bits