Results 1 to 37 of 37

Thread: Page replacement algorithm

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Question Page replacement algorithm

    I have a problem to code a page replacement algorithm simulation in VB.net, I have the random numbers that represent the pages that will be used, and I have been able to put the first pages in to 'memory'. I try to program First-in/first out, Least recently used and optimal, but I have no idea how to do it. Can someone please help me?

    See more here: http://en.wikipedia.org/wiki/Page_re...ent_algorithms
    .NET 2.0
    Last edited by USER_--_NAME; Mar 27th, 2008 at 12:06 PM.

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    Multics to the rescue:

    http://www.multicians.org/an61.html#sXVII

    Then search for:
    Main Memory Replacement Algorithm

    or

    http://www.multicians.org/multics-vm.html

    and search for
    8.4 The Page Fault Handler
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    Thank you, but sorry, that was not what I was looking for.
    I am going to write a simulation in Visual BASIC .net.
    I do understand how the algorithms works, I only have troubles writing them.

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    Mostly what you will find here are people willing to help you with YOUR code. That means you have to put something together and ask for help.

    To get started create an array to simulate memory. If you create it with multi-dimensions you can use the extra dimensions as your page table descr.

    dim VirtMem(10000,3) say

    A Timer will be useful to make Random hits into our virtual memory.

    BTW - What version of Basic are you using?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    I have put something together, and I have tried for days to continue with the code!
    I have the first pages from memory in a one dimensional array right now.
    can it also be a good idea to use array(o), array(2) etc. to page numbers, and array(1), array(3) etc. for page table descr.?

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    version of basic

    I can help with 2005 or 2008
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    .NET 2
    ASP.net 2
    I don't use Visual Studio

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    visual basic express?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    I don't use an IDE. I write in notepad and similar.

  10. #10
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: Page replacement algorithm

    Why would anyone not take advantage of the capabilities of Visual Studio. This is regression at best. Notepad cannot replace intellisense, object Browser, and the various features that make VB such a great environment. VB Express is availalbe for free so why use notepad?
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    I don't know. Anyway, in such a small program will it really help much?
    Maybe I will try it.

  12. #12
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: Page replacement algorithm

    The more power to you if you can do it. Good luck
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  13. #13
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    Download Visual Basic Express 2008 - it is free.

    I am done writing it, and it works as expected, even thrashes when I disable the write of dirty pages.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    I don't have my PC with Windows right now, so I can't download it now.
    and can you please show me the code?

  15. #15
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    Sure. I should get at least a notation in your project, K.
    Last edited by dbasnett; Mar 30th, 2008 at 10:21 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    Thank you very much!
    but I don't know exactly how to compile it (my command line compiler gives me errors) I was thinking to put it in an ASP.net page, any suggestion? Do I have to install Visual Studio to make it work (I am using my PC with Windows now, so I can)

  17. #17
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    You mean the PC you don't have.

    Download Visual Basic Express 2008.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    I have it available now, I did not earlier today (I got it back earlier than expected). I am downloading now.
    Last edited by USER_--_NAME; Mar 27th, 2008 at 05:40 PM.

  19. #19
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    I'll zip and post the whole project.
    Last edited by dbasnett; Mar 28th, 2008 at 06:16 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    Thank you, but it's all too much. I was not looking for something that showed output while simulating. Just some simple algorithms I could put in a ASP.net page or a console window. To count page faults. And as already mentioned, I have a set of random numbers that represent the pages that the 'processes' will need.
    The memory size is stored in a variable (from user input)

  21. #21
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    I am about done with an update that corrects some of the flaws in the original, and more closely emulates the write to backing store. I will post a reply here with a link to the new attachment.

    Sorry you do not feel that it meets your needs. It certainly looks like a Virtual Memory System with a LRU Page Replacement Algorithm.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  22. #22
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    Has hooks for simulating programs causing faults. Currently the faulting program is generated randomly.
    Last edited by dbasnett; Jul 9th, 2008 at 01:51 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    Thank you very much.
    One more question: how do I work with empty arrays without getting errors? (System.NullReferenceException)
    I am translating a program from PHP.

  24. #24
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    why are you working with empty arrays? specific code, specific answers.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  25. #25

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    An array should be copied with references to itself, the array can be set in different places in the code.
    Simple example:
    Code:
    <%
    
    Dim b%, d%, g%
    b=2
    d=1
    g=2
    dim a()
    DIM c(,)
    
    WHILE g < 10
    
    	if a(b) = c(b, d)
         		c(b, d)=c(b -1, d)
    	Else
    
    		c(b, d)=g
    	END if
        
    g = g + 1
    
    END WHILE
    
    %>

  26. #26
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    You should get System.NullReferenceException in the example.

    Code:
    dim a () 'create an empty array
    b=1
    a(b) = 2 'System.NullReferenceException should happen
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  27. #27

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    Exactly!
    how do I avoid that? a similar program in PHP will work. what is the simplest way to avoid it? it looks like On error GoTo would not work here ( anyway it would have been difficult to know where to place the label because the PHP script is full of such things.

  28. #28
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    I am curious about your original problem statement:

    "I have the random numbers that represent the pages that will be used"

    It occurs to me that there must be more information about the simulation system, like

    How much physical memory does it have
    Are the pages the ones causing a page fault
    What is the arrival rate

    etc.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  29. #29

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    That is not a problem anymore, I guess your help was enough for that. But I also use a part of an other program in PHP.

  30. #30
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    Still curious though. I'd like to see if what I wrote produces correct results.

    Glad to hear that you got your array problem fixed, it was pretty easy to fix, huh?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  31. #31

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    It is not tested enough yet, I also need the translation from the PHP script

  32. #32
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    Does that mean I can't know the all of the parameters to the problem? I don't want your work, just a better definition of the problem.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  33. #33
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  34. #34

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    Getting the code I posted now, recently to work without much rewrite.

  35. #35
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    So you aren't going to tell me more details about the original problem("I have a problem to code a page replacement algorithm simulation in VB.net, I have the random numbers that represent the pages that will be used") like
    How much physical memory does it have
    Are the pages the ones causing a page fault
    What is the arrival rate


    OK. Good luck.

    The link I posted will tell you every thing you want to know about arrays.
    Last edited by dbasnett; Mar 30th, 2008 at 10:27 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  36. #36

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: Page replacement algorithm

    System.NullReferenceException is the problem

  37. #37
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Page replacement algorithm

    The link I posted will tell you every thing you want to know about arrays.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width