CNode* CMigrationInfo::FindNodeWithFreeMem(CNode* i_sourceNode, CProcess* i_process) { i_sourceNode->WriteLog("MIGRATION - MEM ISSUES - Searching for destination node to establish migration"); CNode* returnValue = NULL; bool found = false; double maxFreeMem = 0; uint32_t maxIndex = 0; // find out which is the process with the greatest free mem that we can migrate to: if (i_sourceNode->GetAvailableBandwidth() > 0) { for (uint32_t i = 0; i < CMasterSingleton::GetInstance()->GetNodeCount(); ++i) { CNode* currentNode = CMasterSingleton::GetInstance()->GetNode(i); double freeMem = currentNode->GetFreeMem(); if (maxFreeMem < freeMem && i_sourceNode->GetId() != currentNode->GetId() && CanBeDestination(currentNode, i_process)) { maxFreeMem = freeMem; maxIndex = i; found = true; } } // if found is false, we will return a null pointer meaning that the migration should not happen if (found) returnValue = CMasterSingleton::GetInstance()->GetNode(maxIndex); } return returnValue; }