Exemple #1
0
		void process() {
			while(nextOperation) {
				auto operation = nextOperation;
				switch(operation->type) {
				case OperationType::Add: onAdd(operation); break;
				case OperationType::Remove: onRemove(operation); break;
				case OperationType::RemoveAll: onRemoveAll(operation); break;
				default:
					throw std::runtime_error("Unexpected EntityOperation type");
				}

				nextOperation = operation->nextOperation;
				operation->~T();
				memoryManager->free(sizeof(T), alignof(T), operation);
			}
			nextOperation = nullptr;
			lastOperation = nullptr;
		}
Exemple #2
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;
  }
}