memory management - placement alogorithem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kamsmartx
    New Member
    • Oct 2007
    • 20

    #1

    memory management - placement alogorithem

    hi

    i have the problem in this program


    [CODE=java]import java.io.*;
    import java.io.InputSt ream;
    import java.io.OutputS tream;
    import java.io.FileInp utStream;
    import java.io.FileOut putStream;
    import java.io.FileRea der;
    import java.io.FileNot FoundException;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;


    public class placement{
    public static void main(String[]args) throws FileNotFoundExc eption
    {
    String internalFragmen tation;
    String externalFragmen tation;
    int memory,dummycou nt;
    int process;
    int[] bestfit,worstfi t,nextfit,first fit;
    Scanner iFile= new Scanner(new FileReader("pro cesses.txt"));
    Scanner inFile1= new Scanner(new FileReader("mem ory.txt"));


    dummycount=0;
    while (inFile1.hasNex t())
    {
    memory = inFile1.nextInt ();
    dummycount=dumm ycount+1;
    }
    firstfit =new int [dummycount];

    inFile1.close() ;

    System.out.prin tln("------For FirstFit algorithm---------");

    inFile1= new Scanner(new FileReader("mem ory.txt"));

    dummycount=0;
    while (iFile.hasNext( ))
    {inFile1= new Scanner(new FileReader("mem ory.txt"));

    process = iFile.nextInt() ;
    while (inFile1.hasNex t())
    {

    memory = inFile1.nextInt ();
    if ((memory >=process)&&(du mmycount< firstfit.length )&&(firstfit[dummycount]==0))
    {
    firstfit[dummycount]=process;
    System.out.prin tln("memory partition" " " memory " will accomodate process that need" " " +process);
    }
    }


    dummycount++;
    inFile1.close() ;
    }

    iFile.close();



    System.out.prin tln("------For BestFit algorithm---------");


    nextfit =new int [dummycount];



    //System.out.prin tln("------For NextFit algorithm---------");
    dummycount=0;
    iFile= new Scanner(new FileReader("pro cesses.txt"));

    while (iFile.hasNext( ))
    {

    process = iFile.nextInt() ;
    inFile1= new Scanner(new FileReader("mem ory.txt"));
    while (inFile1.hasNex t())
    {

    memory = inFile1.nextInt ();
    if ((memory >=process)&&(du mmycount< nextfit.length) &&(nextfit[dummycount]==0))
    {
    nextfit[dummycount]=process;
    System.out.prin tln("memory partition" " " memory " will accomodate process that need" " " +process);
    }
    }


    dummycount++;

    }
    System.out.prin tln("dummycount " +" "+dummycoun t);

    inFile1.close() ;
    iFile.close();
    System.out.prin tln("------For WorstFit algorithm---------");

    }
    } [/CODE]


    iam work at JSDK 1.6

    the problem is not result the out put ????

    the algorithm is
    first fi that said :
    allocate the first hole that is big enough .searching can start either at the beginning of the set holes or where the previous first fit search ended.wec can stop searching as soon as we fnd a large enough free hole.

    best fit that said :
    allocate the smallest hole that is big enough (the block that is the closet in size ). we must search the entire list ,unless the list is kept ordered by size

    worst fit that said:
    allocate the biggest hole that is big enough (the block that is the closet in size ). we must search the entire list ,unless the list is kept ordered by size

    so
    i wont to enter the process and saved it on to memory txt

    help me
    Last edited by Ganon11; Oct 13 '07, 01:53 PM. Reason: Please use the [CODE] tags provided.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by kamsmartx
    help me
    Sure, what do you need help with? Given those first, next, best and worst fit
    algorithms I'd expected some data structures that mimic actual memory but
    all I see is a lot of file fiddling and some Swing imports.

    How about a simple class that represents a chunk of memory?

    [code=java]
    public class MemoryChunk {
    private int address;
    private int size;
    private boolean free= true;
    //
    public MemoryChunk(int address, int size) {
    this.address= address;
    this.size= size;
    }
    // more methods here
    }
    [/code]

    You should be able to split a free block into a free remainder and a non-free
    used block. You should also implement the join of two adjacent free blocks.

    How's that for starters?

    kind regards,

    Jos

    Comment

    • kamsmartx
      New Member
      • Oct 2007
      • 20

      #3
      sure
      but i cheked the memory but the my prolem is
      how i can tell user to enter volume of process (job) and how to saved it on memory
      supposed that the memory is have 80kb and i wont to enter 4 job ech jo have 30kb how i can use this code to saved it
      this my problem >>>>

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by kamsmartx
        sure
        but i cheked the memory but the my prolem is
        how i can tell user to enter volume of process (job) and how to saved it on memory
        supposed that the memory is have 80kb and i wont to enter 4 job ech jo have 30kb how i can use this code to saved it
        this my problem >>>>
        I apologize, I don't understand your remark; can you rephrase it?

        kind regards,

        Jos

        Comment

        • kamsmartx
          New Member
          • Oct 2007
          • 20

          #5
          ok
          i wont to enter volume of process e.g 20kb to memory i wont to use this code to show how i can saved it on memory

          Comment

          • kamsmartx
            New Member
            • Oct 2007
            • 20

            #6
            any help
            placeeeeeeeeee

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by kamsmartx
              ok
              i wont to enter volume of process e.g 20kb to memory i wont to use this code to show how i can saved it on memory
              Sorry, I still can't understand your question; what I also don't see anywhere in your
              code is a notion of time, i.e. a job takes up a (fixed?) amount of memory during
              so and so much time and then the entire memory block should be released
              again, free for reuse by another job. A second notion of time should be the
              arrival time of the job. That way: arrival time, time length and the amount of
              memory needed enables you to run a simple simulation using your allocation
              strategies: first, next, best and worst fit.

              kind regards,

              Jos

              Comment

              • kamsmartx
                New Member
                • Oct 2007
                • 20

                #8
                ok
                but my problem is no result
                ????
                copy this code and compiler it then show

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by kamsmartx
                  ok
                  but my problem is no result
                  ????
                  copy this code and compiler it then show
                  No, we're not your remote compiler. You compile it and show us the exact compiler
                  diagnostics and the relevant code and tell us what you don't understand about it.
                  That's the way things work here and it's better for the posters (like you) to do
                  things themselves; i.e. it has a higher educational value.

                  kind regards,

                  Jos

                  Comment

                  • kamsmartx
                    New Member
                    • Oct 2007
                    • 20

                    #10
                    ok
                    thank.......... .........

                    Comment

                    Working...