473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

memory management - placement alogorithem

hi

i have the problem in this program


Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.io.InputStream;
  3. import java.io.OutputStream;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.FileReader;
  7. import java.io.FileNotFoundException;
  8. import java.util.*;
  9. import java.awt.*;
  10. import javax.swing.*;
  11.  
  12.  
  13. public class placement{
  14. public static void main(String[]args) throws FileNotFoundException
  15. {
  16. String internalFragmentation;
  17. String externalFragmentation;
  18. int memory,dummycount;
  19. int process;
  20. int[] bestfit,worstfit,nextfit,firstfit;
  21. Scanner iFile= new Scanner(new FileReader("processes.txt"));
  22. Scanner inFile1= new Scanner(new FileReader("memory.txt"));
  23.  
  24.  
  25. dummycount=0;
  26. while (inFile1.hasNext())
  27. {
  28. memory = inFile1.nextInt();
  29. dummycount=dummycount+1;
  30. firstfit =new int [dummycount];
  31.  
  32. inFile1.close();
  33.  
  34. System.out.println("------For FirstFit algorithm---------");
  35.  
  36. inFile1= new Scanner(new FileReader("memory.txt"));
  37.  
  38. dummycount=0;
  39. while (iFile.hasNext())
  40. {inFile1= new Scanner(new FileReader("memory.txt"));
  41.  
  42. process = iFile.nextInt();
  43. while (inFile1.hasNext())
  44.  
  45. memory = inFile1.nextInt();
  46. if ((memory >=process)&&(dummycount< firstfit.length)&&(firstfit[dummycount]==0))
  47. {
  48. firstfit[dummycount]=process;
  49. System.out.println("memory partition" " " memory " will accomodate process that need" " " +process); 
  50. }
  51. }
  52.  
  53.  
  54. dummycount++;
  55. inFile1.close();
  56. }
  57.  
  58. iFile.close();
  59.  
  60.  
  61.  
  62. System.out.println("------For BestFit algorithm---------");
  63.  
  64.  
  65. nextfit =new int [dummycount];
  66.  
  67.  
  68.  
  69. //System.out.println("------For NextFit algorithm---------");
  70. dummycount=0;
  71. iFile= new Scanner(new FileReader("processes.txt"));
  72.  
  73. while (iFile.hasNext())
  74. {
  75.  
  76. process = iFile.nextInt();
  77. inFile1= new Scanner(new FileReader("memory.txt"));
  78. while (inFile1.hasNext())
  79.  
  80. memory = inFile1.nextInt();
  81. if ((memory >=process)&&(dummycount< nextfit.length)&&(nextfit[dummycount]==0))
  82. {
  83. nextfit[dummycount]=process;
  84. System.out.println("memory partition" " " memory " will accomodate process that need" " " +process); 
  85. }
  86. }
  87.  
  88.  
  89. dummycount++;
  90.  
  91. }
  92. System.out.println("dummycount" +" "+dummycount);
  93.  
  94. inFile1.close();
  95. iFile.close(); 
  96. System.out.println("------For WorstFit algorithm---------");
  97.  
  98. }

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
Oct 13 '07 #1
9 2550
JosAH
11,448 Expert 8TB
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?

Expand|Select|Wrap|Line Numbers
  1. public class MemoryChunk {
  2.    private int address;
  3.    private int size;
  4.    private boolean free= true;
  5.    //
  6.    public MemoryChunk(int address, int size) {
  7.       this.address= address;
  8.       this.size= size;
  9.    }
  10.    // more methods here
  11. }
  12.  
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
Oct 13 '07 #2
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 >>>>
Oct 14 '07 #3
JosAH
11,448 Expert 8TB
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
Oct 14 '07 #4
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
Oct 14 '07 #5
any help
placeeeeeeeeee
Oct 15 '07 #6
JosAH
11,448 Expert 8TB
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
Oct 15 '07 #7
ok
but my problem is no result
????
copy this code and compiler it then show
Oct 15 '07 #8
JosAH
11,448 Expert 8TB
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
Oct 15 '07 #9
ok
thank...................
Oct 16 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Philip Lawatsch | last post by:
Hi, I have some questions about whats written in http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.14 (Describing some memory pool) #1 From what i understand this will also work for new...
14
by: phil_gg04 | last post by:
Dear C++ Experts, Over the last couple of months I have been writing my first program using shared memory. It has been something of an "in-at-the-deep-end" experience, to say the least. At...
15
by: mangesh | last post by:
This code is from c++ faq in section 11 : void someCode() { char memory; void* p = memory; Fred* f = new(p) Fred(); f->~Fred(); // Explicitly call the destructor for the placed object }
13
by: Samshayam | last post by:
I have come across the application of placement new in memory mapped i/o in a number of books.I am not able to understand it completely, may be becaues of my lack of knowledge with memory mapped...
7
by: toton | last post by:
Hi, I have a STL vector of of characters and the character class has a Boost array of points. The things are vector<Characterchars; and class Character{ private: array<Point,Npoints; }; Now...
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
13
by: shsingh | last post by:
I have a class A containing some map as data variables. I creat an object of class A on heap by allocatiing memory by using "malloc". This will return me the required memory but the object is not...
5
by: Lagarde Sébastien | last post by:
Hello, I write code to debug new call with following macro: #define new (MemoryManager::Get().setOwner (__FILE__, __LINE__, _FUNCTION-), FALSE) ? NULL : new The setOwner allow to save the...
5
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.