package allocation; import java.util.Scanner; public class MallocSimulator { public static void main(String[] args) { Scanner in = new Scanner(System.in); FreeList list = new FreeList(1024); int answer; int address; do { System.out.println("1. Allocate memory"); System.out.println("2. Free memory"); System.out.println("3. Print free list"); System.out.println("4. Quit"); System.out.print("Enter choice: "); answer = in.nextInt(); System.out.println(); switch(answer) { case 1: System.out.print("Bytes to allocate: "); int bytes = in.nextInt(); address = list.allocate(bytes); if(address < 0) System.out.println("Allocation failed."); else System.out.println("Allocation succeeded! Address: " + address); break; case 2: System.out.print("Address to free: "); address = in.nextInt(); if(list.free(address)) System.out.println("Free succeeded!"); else System.out.println("Free failed. Invalid address."); break; case 3: list.print(); break; } System.out.println(); } while(answer != 4); } }