Example #1
0
void execute(string line, MemoryManager &memManager) {
  string funcName = parseFunction(line);
  if (funcName.compare("alloc") == 0) {
    int pid;
    UNIT size = getAllocParam(line, &pid);
    if (!size) {
      cout << "Parse parameters error: " << line << endl;
    } else {
      if (!memManager.alloc(pid, size)) {
	cout << "No space for process " << pid << endl; 
      }
    }      
  } else if (funcName.compare("realloc") == 0) {
    int pid;
    UNIT size = getReallocParam(line, &pid);
    if (!size) {
      cout << "Parse parameters error: " << line << endl;
    } else {
      if (!memManager.realloc(pid, size)) {
	cout << "No space for process " << pid << endl; 
      }
    }
  } else if (funcName.compare("free") == 0) {
    int pid = getFreeParam(line);
    if (pid == -1) {
      cout << "Parse parameters error: " << line << endl;
    } else {
      if (!memManager.free(pid)) {
	cout << "Free: couldn't find process " << pid << endl;
      }
    }
  } else if (funcName.compare("dump") == 0) {
    memManager.dump();
  } else {
    cout << "Can not parse command: " << line << endl;
  }
}