📄 memory.java
字号:
public class Memory {
private int[] memory;
private static int FREE;
private static int SIZE = 0; //???
private static Memory instence = null;
private Memory() {
memory = new int[SIZE];
for (int i = 0; i < SIZE; i++)
memory[i] = 0;
FREE = SIZE;
}
public static synchronized Memory getInstence() { //获取类的唯一实例
if (instence == null)
instence = new Memory();
return instence;
}
public static void setSize(int size) { //设置内存初始大小,只能在生成实例前调用.
if (instence == null)
Memory.SIZE = size;
else {
getInstence().clear();
Memory.SIZE = size;
instence=new Memory();
}
}
public int getFree() { //获得空闲单元总数
return FREE;
}
public void fenpei(int start, int size) { //分配算法,FREE(空闲单元数)减少size,将分配出去的单元置1.
for (int i = start; i <start+ size; i++) {
this.memory[i] = 1;
}
FREE -= size;
}
public void huishou(int start, int size) { //根据开始点和大小回收内存,将回收段置0.
for (int i = start; i <start+size; i++) {
memory[i] = 0;
}
FREE += size;
}
public int point() {
return SIZE - FREE;
}
public void clear() {
for (int i = 0; i < SIZE; i++)
memory[i] = 0;
FREE = SIZE;
}
public int [] getMmy(){return memory;}
public int get(int i){return memory[i];}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -