Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This exercise will require you to create a Java program that mimics the operation of an Operating System virtual memory capability. Virtual memory is still

This exercise will require you to create a Java program that mimics the operation of an Operating System virtual memory capability. Virtual memory is still used because although the complement of RAM in a modern PC is huge and growing, the size and number of programs that need to be executing simultaneously is growing even faster. Your program will not attempt to emulate a complete virtual memory capability but rather will demonstrate a two-level memory. The two levels will be implemented as a file on disk and a Java array in memory. In real life the virtual memory capability depends on the ability of the operating system to detect the situation when a program tries to execute an instruction outside its protected area of memory. We will not be executing any code in our virtual memory but will restrict ourselves to data storage. We will use virtual memory techniques to store an array of 1000 values in the swap file but use an array of only 100 values in RAM to access the entire 1000-element array. You will create a class definition for a new class, named vMem which will have defined as a class attribute (data member), an actual Java array of 100 8-byte elements of type long (long integer). The class constructor will construct a direct access file large enough to hold 1000 8-byte values (which is 10 times the size of the actual RAM array). The user (your main method for testing) will use the vMem as though it were actually 1000 elements long. But (in the example) the vMem will be actually 100 elements long and will contain only one of the ten 100-element sections of the larger, conceptual memory. When the user attempts to access data outside of the 100 element array, Java will throw an exception; which you will catch, whereupon the catch code will decide which of the stored 100-element pages is needed from the direct-access file. It will find it and replace the data in the 100 element array. The analogy is that the CPU experiences memory as a huge array of 1-byte elements. It creates a swap file where the pieces of a much larger memory are defined. The ram is apportioned to each of the running programs and the apportioning software will allow a program needing 5 megabytes of RAM to exist and execute, using an actual RAM area much smaller. When the in-RAM segment of the program has been used and the CPU attempts to access a part of the larger virtual program, that part is brought into RAM from the swap file on the hard drive. Your swap-file array will be stored in a direct-access file on the hard drive in its full size (1000 elements). The actual array inside the vMem object will be much smaller, 100 elements. You will use the main test program below, that will test the vMem object by attempting to use the entire 1000 elements that it tried to allocate when the vMem was created. This is done by generating an index value between 0 and (1000-1) and then generating a storage value to be stored at the index and immediately read back from that location. Using the random index will insure that the array accesses will not follow any pattern but will be scattered throughout the entire range of 1000 values. When the value is immediately read back it is compared with the value that was stored and any discrepancy is noted as an error. Since the storage-retrieval loop executes 1,000,000 times it will use several minutes of elapsed time.

Further testing: You will add the following functionality to the main program and your exercise will not be considered to be complete until this is complete and error free. You will add a loop which will store a sequence of 1000 descending values in the array. They will then be read and tested to insure that they are still in descending order. Any error will be flagged and the program will be stopped.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago